I'm trying to remove a click handler from an a element, but .off()
does not remove it.
I already looked here and here.
My HTML (which is generated dynamically in document.ready()
event):
<ul id="catalog">
<li data-id="2">
<div class="item">
<div class="image">
<a href=""><center><i class="fa fa-picture-o fa-lg noitemimage"></i></center><span class="txt">My title</span></a>
</div>
<div class="details"><button class="delete btn-primary-grey-s">Delete</button></div>
</div>
</li>
</ul>
Javascript:
$(document).on('click', '#catalog a', function () {
ShowData();
return false;
});
At a user action the following code is called and I want to remove the click handler that was set in the above code. However, after execution I can still click the hyperlink and the above code is still executed.
$.ajax({
type: "GET",
url: "/api/deleteitem/?itemid=" + itemid,
data: "",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) {
//disable the events on this elements' "a" click
//ALL THESE 3 OPTIONS BELOW DO NOT WORK
//$(document).off('click', 'ul#catalog li[data-id=' + itemid + '] a', '**');
//$('ul#catalog li[data-id=' + itemid + '] a').off();
$('ul#catalog li[data-id=' + itemid + '] a').off('click');
}
});
** UPDATE 1 **
$.ajax({
type: "GET",
url: "/api/getitems/?id=" + id ,
data: "",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) {
DYNAMIC HTML CODE GENERATED FROM HERE WORKS DIFFERENTLY??
}
}
});