tadam logo
Did you find an error in the text?
Select this with mouse and press
Ctrl + Enter
Xhtml.co.il Check Spelling
Orphus system

event.which

event.which

Returns: String

Description: For key or button events, this attribute indicates the specific button or key that was pressed.

event.which

version added: 1.1.3

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.

Example

Log what key was depressed.
$('#whichkey').bind('keydown',function(e){ 
  $('#log').html(e.type + ': ' +  e.which );
});  
The output of the code above will be:

Full source

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
                    "http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript" language="javascript">
  $(document).ready(function(){
    $('#whichkey').bind('keydown',function(e){ 
      $('#log').html(e.type + ': ' +  e.which );
    });  
  });
</script>
</head>
<body>
<input id="whichkey" value="type something">
<div id="log"></div>
</body>
</html>
Was this information helpful?
   

Comments