How do i search options via javascript


Is there a way to search select2 options by label via javascript.


Select2 doesn’t provide a programmatic search capability. You can do it manually, though, by setting the value of the Select2’s input field to the search term you want. Something like this will work:


The first line programmatically opens the the Select2, exposing the search field. The second line sets the value of the search field to the desired search term and triggers the input event, which causes the Select2 to display the items that match the value of searchTerm.