jQuery Find option by text and move it to top of select -


i trying find option in select it's text , move option top of select can't seem it, using version 1.9.1.

// move 'untagged' option top of select jquery('#logical_interface_vlan_id option:[text="untagged"]').prependto(jquery('#logical_interface_vlan_id')); 

logical_interface_vlan_id id of select , untagged option text looking for.

the above gives me unrecognized expression syntax error.

i tried this, no errors didn't either:

jquery('#logical_interface_vlan_id').find('option[text="untagged"]').prependto(jquery('#logical_interface_vlan_id')); 

you loop through options , remove , prepend way

jquery('#logical_interface_vlan_id option').each(function() {         if (jquery(this).text() === 'untagged') {             var option = jquery(this);             jquery(this).remove();             jquery('#logical_interface_vlan_id').prepend(option);         }     }); 

Comments

Popular posts from this blog

assembly - 8086 TASM: Illegal Indexing Mode -

Java, LWJGL, OpenGL 1.1, decoding BufferedImage to Bytebuffer and binding to OpenGL across classes -

javascript - addthis share facebook and google+ url -