onKeyPress Vs. onKeyUp and onKeyDown onKeyPress Vs. onKeyUp and onKeyDown javascript javascript

onKeyPress Vs. onKeyUp and onKeyDown


NOTE KeyPress is now deprecated. Use KeyDown instead.

KeyPress, KeyUp and KeyDown are analogous to, respectively: Click, MouseUp, and MouseDown.

  1. Down happens first
  2. Press happens second (when text is entered)
  3. Up happens last (when text input is complete).

The exception is webkit, which has an extra event in there:

keydownkeypresstextInput     keyup

Below is a snippet you can use to see for yourself when the events get fired:

window.addEventListener("keyup", log);window.addEventListener("keypress", log);window.addEventListener("keydown", log);function log(event){  console.log( event.type );}