Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 504
john Avatar asked Mar 30 '11 21:03

john


1 Answers

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
like image 138
Richard Dalton Avatar answered Sep 19 '22 09:09

Richard Dalton