To remove an event listener using jQuery, you can use .off():
$("body").off("keydown", doSomething2);
Remember the method keydownis just a shortcut to .on("keydown", ...).
However, to “disable” them, it would be easier to have only one handler that does different things based on the currently selected view, or both are connected, and each with a short check that the correct view is currently selected.
source
share