tags:

views:

29

answers:

1

Hello to all, This is my first post here. After a few weeks reading and learning here I have a specific question:

$(document).keypress(function(e) {
  if (e.which == 13) { alert('Key press') }; 
});

This runs perfectly; an alert box is shown.

When I try with ESC (code 27) or any other key code, it doesn't run. Any suggestions?

A: 

You need to access the keyCode property, not 'which'

if(e.keyCode == 27) {
Ben Rowe
Thank you for your fast answer, but still the same.Using your code with '13' it's running but with '27'(ESC) or '38' UpArrow, NO WAY...mmm any idea?
Pedro
Ben Rowe
see http://jsfiddle.net/S8YuB/ for a working demo
Ben Rowe
Greats! So simple, so easy.. Thanks!.
Pedro