Possible Duplicate:
Quick way to clear all selections on a multiselect enabled <select> with jQuery?
Dear All.
I have a problem. once i have a multiselect box and i want to clear all the contents of that when i clickon the reset button.
could you please provide me jquery for that?
Thanks.
Satya
The below codes works fine for two dropdowns, but not for more than 2. var $select = $("select[id$='go']"); $select. change(function() { $select . not(this) .
You also can remove the duplicates from the table list firstly, then create the drop down list. Select the column range you want to use in the table, the press Ctrl + C to copy it, and place it to another position by pressing Ctrl + V. Then keep selecting the list, click Data > Remove Duplicates.
I assume you mean clear selection:
//for jQuery >= 1.6
$('select option').removeProp('selected');
//for jQuery < 1.6
$('select option').removeAttr('selected');
To unselect all items if using jQuery 1.6.1 or later:
$('#mySelect').children().removeProp('selected');
or for backwards compatibilty:
$('#mySelect').children().removeAttr('selected');
For simplicity's sake I'm assuming that your HTML is well formed and that your select
only has option
children.
Also, if the list is large and performance is an issue, filter
the list so that you only change the ones that are actually selected - it's arguable whether it's simpler to simply deselect every option or only change the ones that need deselecting:
$('#mySelect').children(':selected').removeProp('selected');
[NB: using :selected
in the second function call is (according to the jQuery docs) more efficient than making a single compound selector]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With