event.which
Categories: Event Object
event.whichReturns: Number
Description: For key or button events, this attribute indicates the specific button or key that was pressed.
-
event.which
version added: 1.0
event.which
normalizes event.keyCode
and event.charCode
. It is recommended to watch event.which
for keyboard key input. For more detail, read about event.charCode on the MDC.
-
Log what key was depressed.
HTML:
<input id="whichkey" value="type something"> <div id="log"></div>
Code:
$('#whichkey').bind('keydown',function(e){ $('#log').html(e.type + ': ' + e.which ); });
Results:
"keydown" 74