Which keycode for escape key with jQuery

Posted by Shishant on Stack Overflow See other posts from Stack Overflow or by Shishant
Published on 2009-07-21T15:39:25Z Indexed on 2010/05/19 0:30 UTC
Read the original article Hit count: 364

Filed under:
|

I have two functions. When enter is pressed the functions runs correctly but when escape is pressed it doesn't. What's the correct number for the escape key?

$(document).keypress(function(e) { 
    if (e.which == 13) { $('.save').click(); }    // enter (works as expected)
    if (e.which == 27) { $('.cancel').click(); }  // esc   (does not work)
});

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about JavaScript