Jquery select all values in a multiselect dropdown
I have a multi-select html dropdown. I want to programatically (via jquery) select开发者_运维技巧 all values in the dropdown. How can I do this?
Where the select has the id test
$('#test option').attr('selected', 'selected');
JSFiddle Example
Or as Ryan mentioned you can use .prop
$('#test option').prop('selected', true); // or pass false to deselect them
Simply do $("#dropdown").val([0, 1, 2, 3])
where 0
, 1
, 2
, 3
the values you want to select.
精彩评论