2

I have connected select-2 plugin to my select element and now I would like to assign one event to it: to reload the form after clicking .select2-search-choice-close, but I'm unable to bind any event to this element.

Before binding the event I have tried unbinding all events and changing parent's href attribute:

$('.select2-choice').attr('href', '#'); // remove javascript:void(0) 
$('.select2-search-choice-close').off();

but still:

$('#dashboard').on('click', '.select2-search-choice-close', function(e) {
                    e.preventDefault();
                    alert('test');
                    console.log('test');
                };

none of this happen when I click .select2-search-choice-close.

We are using Version: 3.5.2 and I can't change it unfortunately.

van_folmert
  • 4,257
  • 10
  • 44
  • 89

1 Answers1

2

use change event

$('#dashboard').on("change", function (e) {alert('test');});

Jatin Bhole
  • 176
  • 7
  • You probably mean `$('#dashboard select').on("change", function (e) {alert('test');});` and check if the value changed to empty - that is a good workaround, haven't thought of that! But I will still wait to see if anyone knows why that `.select2-search-choice-close` doesn't allow binding any custom events. – van_folmert Feb 19 '16 at 10:27