I'm not asking this because I need a work-a-around. I have one that works fine, but I want to know WHY it doesn't. Is this bug in Javascript (or JQuery because I was using the JQuery .keypress
handler) or is there a specific reason why this is so?
Holding down the backspace key deletes text until there's no more text to the left or above the cursor or you let go of the key. People often hold down the backspace key to delete a lot of text. However, it's faster to select all the text and then press the delete key once.
Once you get the key of the pressed button, then match it with the Backspace key code. A Backspace key keycode it 8. Use keydown instead of keypress . The problem with backspace probably is, that the browser will navigate back on keyup and thus your page will not see the keypress event.
Pressing Backspace deletes text to the left (backwards) of the cursor. For example, if you click at the end of the example text below and press delete, nothing happens because there's no text to the right. However, if you press the Backspace key, the end of the text would begin to be deleted.
The keypress
event is designed for handling a character typed by the user rather than detecting keyboard activity and the delete and backspace keys do not generate characters. Some browsers blur this line somewhat but the general principle is that the keyup
and keydown
events are there to detect any key being pressed and telling you about which key it is while keypress
is for detecting an actual character being typed.
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