JQuery: how to select multiple items in html dropdown?

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

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

thank

+3
source share
1 answer

Given:

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

Do it:

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

This will select all of them. This is the best I can give you, without a more specific question.

+4
source

Source: https://habr.com/ru/post/1734407/


All Articles