Archive

Archive for the ‘jquery’ Category

Remove all the items in a drop down list except the first using Jquery

November 6, 2009 Wes Leave a comment

I needed a drop down list to be populated from a selection in another drop down list. Each select should change the options listed in the second list. Using Jquery it was easy to remove all the options and rebuild the list, but I wanted to keep the first option. I finally found the solution searching the Jquery site and it’s quite simple.

selection.children('option:not(:first)').remove();

Where selection is the id of the drop down list. I hope this helps somebody not spend the hour it took me to figure it out.

Categories: jquery