Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to trap the backspace key using jQuery? [duplicate]

Tags:

jquery

It does not appear the jQuery keyup, keydown, or keypress methods are fired when the backspace key is pressed. How would I trap the pressing of the backspace key?

like image 721
ChrisP Avatar asked Feb 08 '11 16:02

ChrisP


People also ask

How do I restrict Backspace in JavaScript?

Use the onkeydown event and preventDefault() method to Disable Backspace and Delete key in JavaScript. Backspace char code is 8 and deletes key char code is 46.

What is Keyup and Keydown in jQuery?

jQuery keyup() Method The order of events related to the keyup event: keydown - The key is on its way down. keypress - The key is pressed down. keyup - The key is released.


1 Answers

try this one :

 $('html').keyup(function(e){if(e.keyCode == 8)alert('backspace trapped')})   
like image 104
Prakash Avatar answered Oct 08 '22 00:10

Prakash