javascript – How to detect escape key press with pure JS or jQuery?



javascript – How to detect escape key press with pure JS or jQuery?

javascript - How to detect escape key press with pure JS or jQuery?

#short
#javascript
#jquery
#keyevent
#jquery-events
Possible Duplicate:
Which keycode for escape key with jQuery

How to detect escape key press in IE, Firefox and Chrome?
Below code works in IE and alerts 27, but in Firefox it alerts 0
$(‘body’).keypress(function(e){
alert(e.which);
if(e.which == 27){
// Close my modal window
}
});
becoming deprecated: https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/keyCode
Which keycode for escape key with jQuery: https://stackoverflow.com/questions/1160008/which-keycode-for-escape-key-with-jquery