How to call event in Select2 Example

  • 18-01-2023
  • Jquery
  • Haresh Chauhan

If you want to call an event when you are using the select2 autofill dropdown, the method little bit different than we normally use for calling an event in jquery through the class and ids from the tags.

So if you are using the select2 dropdown and want to fire any event like change, click, etc event, I will tell you how to select2 event call.

If you trying to call an event using the select2 dropdown and the select2 event not working, then this post will help you to fix the event calling issue in the select2 dropdown.

I will tell you how to call an event while you using the select2 autofill dropdown plugin, below I was given an example of a call change event from the select2 tags. just follow an example and apply in your application.

Style & Script

Call the style link and script in your application at the top of the head application page. Both scripts must be required for the use Select2 autofill dropdown.

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

Select Tag

Below example call a change using the select2 drop down, follow the sample code and execute in your application.

Given the class to the select tag "search-address", when I change on the class the change event will call from the script and console log "ok" as i given.

<select class="search-address form-control" id="change-add" name="state"></select>

Ajax Dynamic Data Call

    ajax: {
        url: "URL FOR GET DATA",
        dataType: 'json',
        type: "GET",
        quietMillis: 50,
        data: function (term) {
            return {
                term: term
        processResults: function (data) {
            return {
                results: $.map(, function (item) {
                    return {

Solution 1

var $eventSelect = $(".search-address");

$eventSelect.on("change", function (e) { 

Solution 2

$(".select2").on("change", function () { alert() });

We always thanks to you for reading our blogs.


Dharmesh Chauhan

(Swapinfoway Founder)

Hello Sir, We are brothers origin from Gujarat India, Fullstack developers working together since 2016. We have lots of skills in web development in different technologies here I mention PHP, Laravel, Javascript, Vuejs, Ajax, API, Payment Gateway Integration, Database, HTML5, CSS3, and Server Administration. So you need our service Please Contact Us


Haresh Chauhan


We Are Also Recommending You :