<select size="2">
<option selected="selected">Input your option</option>
<option>Input your option</option>
</select>
What is the best way, using jQuery, to elegantly unselect the option?
<select size="2">
<option selected="selected">Input your option</option>
<option>Input your option</option>
</select>
What is the best way, using jQuery, to elegantly unselect the option?
Answers so far only work for multiple selects in IE6/7; for the more common non-multi select, you need to use:
$("#selectID").attr('selectedIndex', '-1');
This is explained in the post linked by flyfishr64. If you look at it, you will see how there are 2 cases - multi / non-multi. There is nothing stopping you chaning both for a complete solution:
$("#selectID").attr('selectedIndex', '-1').find("option:selected").removeAttr("selected");
Thanks a lot for the solution.
The solution for single choice combo list works perfectly. I found this after searching on many sites.
$("#selectID").attr('selectedIndex', '-1').children("option:selected").removeAttr("selected");
Set a id in your select, like:
<select id="foo" size="2">
Then you can use:
$("#foo").prop("selectedIndex", 0).change();