I have this code, I would need programmatically overridde or remove onkeydown from document (for example using a simple condition)
document.onkeydown = function (f) {
myMethod();
};
Any idea how to do it?
Definition and Usage The onkeydown attribute fires when the user is pressing a key (on the keyboard).
The keydown event is fired when a key is pressed. Unlike the deprecated keypress event, the keydown event is fired for all keys, regardless of whether they produce a character value. The keydown and keyup events provide a code indicating which key is pressed, while keypress indicates which character was entered.
document.onkeydown = null
You could use jquery to do your event handeling for you, the method you use is less commonly used and doesn't allow multiple subscribers.
Look at the documentation here:
http://api.jquery.com/on/
example:
$(document).on("keydown", function(){
doStuff();
})
// unsubscribe all handlers
$(document).off("keydown");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With