Is there a way to detach and reattach event listeners assuming I don't know the function that was attached in the first place?
//Unknown click function
$(target).click(function(e){
//some function
});
//code to detach click function
$(target).mousedown(function(e){
if(/*something*/){
//The next line does not work. What could be done instead?
this.clickFunction = $(target).click;
$(target).off("click");
}
});
//code to reattach click function
$(target).mouseup(function(e){
if(this.clickFunction){
$(target).click(this.clickFunction);
this.clickFunction = null;
}
});
jQuery saves the event functions internally as:
Where "target" is a DOM element not a jQuery object.
https://stackoverflow.com/a/2518441/806777
So the example code would be:
https://jsfiddle.net/UziTech/176fzorn/