Hi, just wondering how it's possible to un-select the select option box, i used .remove() but this actually removes the text from the select box,
is there any other way.
thanks
Hi, just wondering how it's possible to un-select the select option box, i used .remove() but this actually removes the text from the select box,
is there any other way.
thanks
$('#mySelectBox :selected').attr('selected', '');
Where #mySelectBox is the id of your select element.
These cases vary for select boxes with single options and select boxes with multiple options.
For select boxes with single options:
<select id='selectbox'>
The jQuery code:
$('#button').click(function() {
$('#selectbox').attr('selectedIndex', '-1');
});
Note: you need this variant to make it work in Internet Explorer. The example below also works for single option textboxes in Internet Explorer.
For select boxes with multiple options:
<select id='selectbox' multiple='multiple'>
The jQuery code:
$('#button').click(function() {
$('#selectbox option').attr('selected', 'false');
});