Search code examples
javascriptevent-handlingdom-eventskeypress

Arrow Keys reading as '0' in keypress event handler


Debugging with Firebug in Firefox 8.0.1, I attach a keypress event handler to an editable div. Every key press shows correctly in the console except the arrow keys, for which e.which in the console is showing up as 0.

How can I get the keycodes for the up and down arrow keys?


Solution

  • It seems that you can't use keypress for the arrow keys, only keyup and keydown:

    Binding arrow keys in JS/jQuery