I am trying to remove the keydown event that I have created using the following code:
$(document).keydown(function(e) {
alert("Key Down");
});
when I am using the following code:
$(document).off('keydown');
it throws the following error:
Uncaught TypeError: Object [object Object] has no method 'off'
can someone point me to the correct way to un-register from the keydown
event?
Unbind all keydown
handlers from document
:
$(document).unbind('keydown');
Or to make sure you only unbind that specific handler:
function myHandler(e) {
alert("Key Down");
}
$(document).keydown(myHandler);
// later
$(document).unbind('keydown', myHandler);
http://api.jquery.com/unbind
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