Wednesday, June 5, 2024
 Popular · Latest · Hot · Upcoming
170
rated 0 times [  172] [ 2]  / answers: 1 / hits: 19855  / 13 Years ago, wed, march 30, 2011, 12:00:00

I have a multi-select html dropdown. I want to programatically (via jquery) select all values in the dropdown. How can I do this?


More From » jquery

 Answers
24

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

[#93003] Tuesday, March 29, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
blair

Total Points: 384
Total Questions: 108
Total Answers: 86

Location: Northern Ireland
Member since Tue, May 5, 2020
4 Years ago
blair questions
Sat, Feb 12, 22, 00:00, 2 Years ago
Wed, Aug 25, 21, 00:00, 3 Years ago
Sat, Jul 10, 21, 00:00, 3 Years ago
Tue, Aug 25, 20, 00:00, 4 Years ago
;