JavaScript Answers

How to Limit Number of Tags with jQuery Select2 Drop Down?

Spread the love

To limit number of tags with jQuery Select2 drop down, we can set the maximumSelectionLength property to the max number of values we can select.

For instance, we can write:

<link href="" rel="stylesheet" />
<script src=""></script>

<select id="select2" multiple>
  <option>Some Text</option>
  <option>Other Text</option>

We create a select element with the multiple attribute.

Then we write:

  maximumSelectionLength: 3

We call select2 with an object with the maximumSelectionLength property set to 3.

Now we can only select 3 choices max.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published.