I am trying to implement a keystroke function that removes a div when the user presses Esc
. This works for Firefox and IE with the following code:
$("body").keypress(function(e) { alert("any key pressed"); if (e.keyCode == 27) { alert("escape pressed"); } });
If I press any key, the first alert
displayed, and if I delete the Escape, the second alert
displayed.
However, this does not work with Chrome. The first alert
always displayed if I press any of the letter keys, but not when I press Escape, Tab, Space or any of the numbers.
Why was that? Is there a way to get Chrome to respond to these keystrokes?
jquery google-chrome keypress
DaveDev Oct 10 2018-10-10 16:14
source share