I am trying to add a link in select2 options list. and I want to bind an event. It is working fine in chrome and firefox. But it is not working in IE(9/10/11). I tried all the alternatives, cancelbubble, returnValue But none is working.
When I click on the hyperlink with class categoryDelete
It is propagating the event to li option and not even executing my custom mouseup event in IE.
I also tried this answer in stack overflow. I used templateResult
for adding the link to select2 options. where as in the above link they used formatResult
. Does it make any difference?
Here is my code.
$("#ContentPlaceHolder1_tags").select2({
dropdownParent: "#dropdownParent",
placeholder: "Select category",
templateResult: function (item) { return '<a href="javascript:;" class="categoryDelete"></a>' + item.text },
escapeMarkup: function(m) { return m },
allowClear: true,
tags: true,
closeOnSelect: false
});
// adding event for link inside select2 options li
$(".categoryDelete").mouseup(function (event) {
event = event || window.event;
event.preventDefault();
event.stopPropagation();
alert("clicked delete link");
});