We're looking for a user researcher to understand the needs of developers and designers. Is this you or someone you know? Check out the post: https://mzl.la/2IGzdXS

event.which Redirect 1

« DOM Reference


Returns the numeric keyCode of the key pressed, or the character code (charCode) for an alphanumeric key pressed.


var keyResult = event.which;

keyResult contains the numeric code for a particular key pressed, depending on whether an alphanumeric or non-alphanumeric key was pressed. Please see charCode and keyCode for more details.


<title>charCode/keyCode/which example</title>

<script type="text/javascript">

function showKeyPress(evt)
alert("onkeypress handler: \n"
      + "keyCode property: " + evt.keyCode + "\n"
      + "which property: " + evt.which + "\n"
      + "charCode property: " + evt.charCode + "\n"
      + "Character Key Pressed: "
      + String.fromCharCode(evt.charCode) + "\n"

function keyDown(evt)
alert("onkeydown handler: \n"
      + "keyCode property: " + evt.keyCode + "\n"
      + "which property: " + evt.which + "\n"



<p>Please press any key.</p>

Note: The above example code fails in Firefox 9 due to bug 696020.


Not part of any specification.

Document Tags and Contributors

Last updated by: Sheppy,