Reputation: 522
I can successfully stop all keys from being pressed with:
$this.keydown(false);
How can I disable all keys with the exception of the backspace key?
Upvotes: 4
Views: 4127
Reputation: 224906
Check the keyCode
of the event argument:
$this.keydown(function(e) {
if(e.keyCode !== 8) {
e.preventDefault();
}
});
Upvotes: 13
Reputation: 324620
Use a callback, check the keycode of the pressed key, if it's the backspace key then allow it, otherwise block.
Upvotes: 1