I have following code:
myCustomMethod(function(){
$(document).on('click','#element',function(){
console.log('First call');
});
});
setTimeout(function(){
myCustomMethod(function(){
$(document).on('click','#element',function(){
console.log('Second call, event first call should be destroyed');
});
});
},2000);
function myCustomMethod(funcn){
funcn();
}
When I test with my browser, I clicked #element console show up First call
but after 2 sec I click again it shows
First call
Second call, event first call should be destroyed
I want to remove the event listener if it is modified (the part below)
Old
$(document).on('click','#element',function(){
console.log('First call');
});
New
$(document).on('click','#element',function(){
console.log('Second call, event first call should be destroyed');
});
only fires console.log('Second call, event first call should be destroyed');
thanks a lot