Prevent onclick being attached to all items.
Hey all. I am having this problem. I have added a button to a select2 input field.
The problem seems to be that the click event is being bound to each item in the a.$results.
I want the click to be only on the button. I have a jsFiddle set up with the problem
https://jsfiddle.net/sm1fo5d0/10/
Thanks in advance.
- let a = $(this).data('select2');
- if (!$('.select2-link').length) {
- a.$results.parents('.select2-results')
- .append('<div class="select2-link select2-close"><a>Close</a></div>')
- .on('click', function (b) {
- alert('I\'ve been clicked');
- //a.trigger('close');
- });
- }