Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why isn't backspace being detected using jquery keypress event?

Tags:

Why isn't backspace being detected using jquery keypress event?

$("#field").keypress(function(event){alert(event.which);}); 
like image 400
Babiker Avatar asked Dec 11 '10 19:12

Babiker


People also ask

Why backspace is not working in keypress?

Try "onkeydown" instead of "onkeypress". KeyPress event is invoked only for character (printable) keys, KeyDown event is raised for all including nonprintable such as Control, Shift, Alt, BackSpace, etc. Using a variety of different examples, we have learned how to solve the Javascript Keypress Backspace Not Working.

Is backspace a keypress event?

The KeyPress event is not raised by non-character keys other than space and backspace; however, the non-character keys do raise the KeyDown and KeyUp events.

How does jQuery detect keyboard press?

The keypress() method in jQuery triggers the keypress event whenever browser registers a keyboard input. So, Using keypress() method it can be detected if any key is pressed or not.


1 Answers

Try using keydownand keyupfunctions instead for IE.

Javascript e.keyCode doesn't catch Backspace/Del in IE

like image 158
mdarwi Avatar answered Oct 07 '22 17:10

mdarwi