Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

34 lines (34 sloc) 1.594 kb
<?xml version="1.0"?>
<entry type="property" name="event.which" return="Number">
<title>event.which</title>
<signature>
<added>1.1.3</added>
</signature>
<desc> For key or mouse events, this property indicates the specific key or button that was pressed. </desc>
<longdesc>
<p>The <code>event.which</code> property normalizes <code>event.keyCode</code> and <code>event.charCode</code>. It is recommended to watch <code>event.which</code> for keyboard key input. For more detail, read about <a href="https://developer.mozilla.org/en/DOM/event.charCode#Notes">event.charCode on the MDC</a>. </p>
<p><code>event.which</code> also normalizes button presses (<code>mousedown</code> and <code>mouseup</code>events), reporting <code>1</code> for left button, <code>2</code> for middle, and <code>3</code> for right. Use <code>event.which</code> instead of <code>event.button</code>. </p>
</longdesc>
<example>
<desc>Log which key was depressed.</desc>
<code><![CDATA[$('#whichkey').bind('keydown',function(e){
$('#log').html(e.type + ': ' + e.which );
}); ]]></code>
<html><![CDATA[
<input id="whichkey" value="type something">
<div id="log"></div>]]></html>
</example>
<example>
<desc>Log which mouse button was depressed.</desc>
<code><![CDATA[
$('#whichkey').bind('mousedown',function(e){
$('#log').html(e.type + ': ' + e.which );
});
]]></code>
<html><![CDATA[
<input id="whichkey" value="type something">
<div id="log"></div>]]></html>
</example>
<category slug="events/event-object"/>
<category slug="version/1.1.3"/>
</entry>
Jump to Line
Something went wrong with that request. Please try again.