Skip to content Skip to sidebar Skip to footer

Close Any Select2 Dropdowns Via Jquery

Anyone know how to close a Select2 programatically without knowing the ID? Just basically, if there's a Select2 open, close it. (If someone opens a modal (containing a Select2), op

Solution 1:

Okay, I got this figured out. Add a unique (not class="select2") class to all the Select2 dropdowns you have in modals, and then use this code:

// If a Modal is hidden, close any open Select2 contained therein - so it doesn't lag behind
$(document).on('hide.bs.modal', '.modal', function() {
   $(".select2-close").select2("close");
}); 

That seems to work well. (In this case I made a class called select2-close )

Post a Comment for "Close Any Select2 Dropdowns Via Jquery"