Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best way to unselect a <select> in jQuery?

Tags:

jquery

select

People also ask

Which is correct unselect or deselect?

Dictionaries (Merriam-Webster and New Oxford American Dictionary) have deselect but not unselect. The NOAD defines deselect as “turn off (a selected feature) on a list of options on a computer menu”, which is what you want.

Which button is used to select or unselect an option?

Pressing the Ctrl key, you can click, or click-and-drag to deselect any cells or ranges within a selection.

How do I select a specific Dropdownlist using jQuery?

Syntax of jQuery Select Option$(“selector option: selected”); The jQuery select option is used to display selected content in the option tag. text syntax is below: var variableValue = $(“selector option: selected”).


Use removeAttr...

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

Or Prop

$("option:selected").prop("selected", false)

There are lots of answers here but unfortunately all of them are quite old and therefore rely on attr/removeAttr which is really not the way to go.

@coffeeyesplease correctly mentions that a good, cross-browser solution is to use

$("select").val([]);

Another good cross-browser solution is

// Note the use of .prop instead of .attr
$("select option").prop("selected", false);

You can see it run a self-test here. Tested on IE 7/8/9, FF 11, Chrome 19.


Simplest Method

$('select').val('')

I simply used this on the select itself and it did the trick.

I'm on jQuery 1.7.1.


It's a been a while since asked, and I haven't tested this on older browsers but it seems to me a much simpler answer is

$("#selectID").val([]);

.val() works for select as well http://api.jquery.com/val/