Prevent onclick being attached to all items.

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.

  1. let a = $(this).data('select2');
  2. if (!$('.select2-link').length) {
  3. a.$results.parents('.select2-results')
  4.                 .append('<div class="select2-link select2-close"><a>Close</a></div>')
  5.                 .on('click', function (b) {

  6.                     alert('I\'ve been clicked');
  7.                     //a.trigger('close');
  8.                 });
  9.         }