How to select a select type = multiple - jQuery
What is the best way to select ALL options that are in a <select>
th开发者_如何学Pythonat is set as "multiple" ?
Simple using the Has Attribute Selector...
$("select[multiple] option");
This checks for the existence of the multiple
attribute on the select tag, and grabs all the options within it.
From the jQuery documentation
.val()
The .val()
method is primarily used to get the values of form elements. In the case of <select multiple="multiple">
elements, the .val()
method returns an array containing each selected option.
To select all options just use $("select option")
or to specifically target multiple use @Josh's answer $("select[multiple] option");
精彩评论