jQuery Event Keypress: Which key was pressed?

Posted by BlaM on Stack Overflow See other posts from Stack Overflow or by BlaM
Published on 2008-11-19T14:59:19Z Indexed on 2010/05/07 15:38 UTC
Read the original article Hit count: 289

Filed under:
|
|
|
|

With jQuery, how do I find out which key was pressed when I bind to the keypress event?

$('#searchbox input').bind('keypress', function(e) {});

I want to trigger an submit when ENTER is pressed.

[Update]

Even though I found the (or better: one) answer myself, there seems to be some room for variation ;)

Is there a difference between keyCode and which - especially if I'm just looking for ENTER, which will never be a unicode key?

Do some browsers provide one property and others provide the other one?

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about bind