I have this:
$(function(){
//remove keydown doSomething2
$("body").keydown(doSomething1);
});
In other view I have this:
$(function(){
//remove keydown doSomething1
$("body").keydown(doSomething2);
});
How to do what’s in the comment? With my current code, both doSomething1 and doSomething2 are called. I want do disabled the one I dont need.
To remove an event listener with jQuery, you can use
.off():Remember the
keydownmethod is just a shortcut for.on("keydown", ...).However, to “disable” them it might be easier to have only one handler that executes different things based on the current selected view, or have both of them bound and each with a short check that the right view is currently selected.