jqueryHow do I use jQuery Select2 to select multiple options?
To use jQuery Select2 to select multiple options, you need to use the multiple attribute in the select tag. The multiple attribute allows the user to select more than one option from the dropdown list.
For example:
<select id="example" multiple="multiple">
<option value="1">Option 1</option>
<option value="2">Option 2</option>
<option value="3">Option 3</option>
<option value="4">Option 4</option>
<option value="5">Option 5</option>
</select>
Then, you need to initialize the Select2 plugin by using the following code:
$('#example').select2({
placeholder: 'Select an option',
multiple: true // allows multiple selection
});
After that, you can select multiple options by pressing the Ctrl key and clicking on the desired options.
The parts of the code are:
selecttag withmultipleattribute - defines the select box and allows multiple selectionselect2initialization - initializes the Select2 pluginCtrlkey - allows multiple selection
Helpful links
More of Jquery
- How can I get the y position of an element using jQuery?
- How do I use jQuery ZTree to create a hierarchical tree structure?
- How do I use jQuery to zoom in or out on an element?
- How do I use a jQuery UI Slider?
- How do I generate a QR code using jQuery?
- How do I use a jQuery x-csrf-token?
- How do I create a jQuery widget?
- How can I use jQuery to control the visibility of an element?
- How do I use jQuery to scroll to a specific element on a page?
See more codes...