Jquery select all the values ​​in the "Multiselect" dropdown

I have a dropdown with several html favorites. I want to programmatically (via jquery) select all the values ​​in a dropdown list. How can i do this?

+8
javascript jquery html
source share
2 answers

If the element has an id test

$('#test option').attr('selected', 'selected'); 

JSFiddle example

Or, as Ryan said, you can use .prop

 $('#test option').prop('selected', true); // or pass false to deselect them 
+20
source share

Just $("#dropdown").val([0, 1, 2, 3]) , where 0 , 1 , 2 , 3 values ​​you want to select.

0
source share

All Articles