Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery: how to select multiple items in a html dropdown list?

Tags:

jquery

I would like to know how can I use jQuery to select multiple items without having to press the SHIFT button on my keyboard in a simple html dropdown element:

<select>
<option></option>
<option></option>
<option></option>
</select>

thanks

like image 867
aneuryzm Avatar asked Mar 13 '26 01:03

aneuryzm


1 Answers

Given:

<select multiple="multiple" id="foo">
<option>1</option>
<option>2</option>
<option>3</option>
</select>

Do this:

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

That would select all of them. That's the best I can give you, without a more specific question.


Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!