How would you dynamically arrange the <option select> list using jQuery?

If I have a drop-down list and a list, is there a way to order a list based on a drop-down list using jQuery? An example will be helpful.

+1
jquery
Mar 19 '09 at 0:05
source share
1 answer

This changes the order in the drop-down list. You will need to set the order depending on your own criteria:

<select id="the-select"> <option value="1">First option</option> <option value="2">Second option</option> </select> <script type="text/javascript"> //<![CDATA[ $(function (){ $("#the-select option[value=2]").insertBefore("#the-select option[value=1]"); }); //]]> </script> 
+2
Mar 19 '09 at 0:12
source share



All Articles