is there a way to unselect all items of a listbox using jquery without looping through each item?
+1
A:
jQuery is designed to work with multiple elements at the same time:
$(listboxSelector).find("option").attr("selected", false);
Matti Virkkunen
2010-04-04 16:03:48
+2
A:
The shortest way is this method:
$("#myListBox").val([]);
This sets the value to an empty array, meaning select no values. .val()
takes an array in the case of a <select multiple>
element. Note that $("select").val('');
also works here :)
Nick Craver
2010-04-04 16:06:13