Quick way to clear all selections on a multiselect enabled <select> with jQuery?

CloudMeta picture CloudMeta · Feb 12, 2010 · Viewed 110k times · Source

Do I have to iterate through ALL the and set remove the 'selected' attribute or is there a better way?

Answer

meagar picture meagar · Feb 12, 2010

Simply find all the selected <option> tags within your <select> and remove the selected attribute:

$("#my_select option:selected").removeAttr("selected");

As of jQuery 1.6, you should use .prop instead of removing the attribute:

$("#my_select option:selected").prop("selected", false);