tags:

views:

1224

answers:

5
<select size="2">
<option selected="selected">Input your option</option>
<option>Input your option</option>
</select>

How to do it elegantly?

+1  A: 
$(option).removeAttr('selected') //replace 'option' with selected option's selector
Brandon H
A: 

A quick google found this post that describes how to do what you want for both single and multiple select lists in IE. The solution seems pretty elegant as well:

$('#clickme').click(function() {
        $('#selectmenu option').attr('selected', false);

});
Jeff Paquette
+3  A: 

Use removeAttr...

$("option:selected").removeAttr("selected");
Ei Maung
A: 
$("option:selected").attr("selected", false);
BranTheMan
+1  A: 

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').children("option:selected").removeAttr("selected");
thetoolman