Reputation: 2853
I have a multi-select html dropdown. I want to programatically (via jquery) select all values in the dropdown. How can I do this?
Upvotes: 9
Views: 20348
Reputation: 35793
Where the select has the id test
$('#test option').attr('selected', 'selected');
Or as Ryan mentioned you can use .prop
$('#test option').prop('selected', true); // or pass false to deselect them
Upvotes: 21
Reputation: 437336
Simply do $("#dropdown").val([0, 1, 2, 3])
where 0
, 1
, 2
, 3
the values you want to select.
Upvotes: 0