Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

Revision 932043 of MouseEvent.which

  • Revision slug: Web/API/MouseEvent/which
  • Revision title: MouseEvent.which
  • Revision id: 932043
  • Created:
  • Creator: cvrebert
  • Is current revision? No
  • Comment note standard alternatives

Revision Content

{{APIRef("DOM Events")}}{{Non-standard_header}}

The MouseEvent.which read-only property indicates which button was pressed on the mouse to trigger the event. The standard alternatives to this property are {{ domxref("MouseEvent.button") }} and {{ domxref("MouseEvent.buttons") }}.

Syntax

var buttonPressed = instanceOfMouseEvent.which

Return value

A number representing a given button:

  • 0: No button
  • 1: Left button
  • 2: Middle button (if present)
  • 3: Right button

For a mouse configured for left-handed use, the button actions are reversed. In this case, the values are read from right to left.

Specification

{{DOM0}}

Browser compatibility

{{CompatibilityTable}}

Feature Firefox (Gecko) Chrome Internet Explorer Opera Safari
Basic support {{CompatGeckoDesktop(1)}}[1] 1.0 9.0 5.0 1.0
Feature Firefox Mobile (Gecko) Android IE Mobile Opera Mobile Safari Mobile
Basic support {{ CompatGeckoMobile(1) }} [1] {{CompatVersionUnknown}} {{CompatVersionUnknown}} {{CompatVersionUnknown}} {{CompatVersionUnknown}}

[1] On {{event("mousemove")}} events, the which property is incorrectly always set to 1 {{bug(1048294)}}.

See also

  • {{ domxref("MouseEvent") }}

Revision Source

<p>{{APIRef("DOM Events")}}{{Non-standard_header}}</p>

<p>The <strong><code>MouseEvent.which</code></strong> read-only property indicates which button was pressed on the mouse to trigger the event. The standard alternatives to this property are {{ domxref("MouseEvent.button") }} and {{ domxref("MouseEvent.buttons") }}.</p>

<h2 id="Syntax">Syntax</h2>

<pre class="syntaxbox">
var buttonPressed = instanceOfMouseEvent.which
</pre>

<h3 id="Return_value">Return value</h3>

<p>A number representing a given button:</p>

<ul>
 <li><code>0</code>:&nbsp;No button</li>
 <li><code>1</code>: Left button</li>
 <li><code>2</code>: Middle button (if present)</li>
 <li><code>3</code>: Right button</li>
</ul>

<p>For a mouse configured for left-handed use, the button actions are reversed. In this case, the values are read from right to left.</p>

<h2 id="Specification">Specification</h2>

<p>{{DOM0}}</p>

<h2 id="Browser_compatibility" name="Browser_compatibility">Browser compatibility</h2>

<p>{{CompatibilityTable}}</p>

<div id="compat-desktop">
<table class="compat-table">
 <tbody>
  <tr>
   <th>Feature</th>
   <th>Firefox (Gecko)</th>
   <th>Chrome</th>
   <th>Internet Explorer</th>
   <th>Opera</th>
   <th>Safari</th>
  </tr>
  <tr>
   <td>Basic support</td>
   <td>{{CompatGeckoDesktop(1)}}<sup>[1]</sup></td>
   <td>1.0</td>
   <td>9.0</td>
   <td>5.0</td>
   <td>1.0</td>
  </tr>
 </tbody>
</table>
</div>

<div id="compat-mobile">
<table class="compat-table">
 <tbody>
  <tr>
   <th>Feature</th>
   <th>Firefox Mobile (Gecko)</th>
   <th>Android</th>
   <th>IE Mobile</th>
   <th>Opera Mobile</th>
   <th>Safari Mobile</th>
  </tr>
  <tr>
   <td>Basic support</td>
   <td>{{ CompatGeckoMobile(1) }} [1]</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatVersionUnknown}}</td>
  </tr>
 </tbody>
</table>
</div>

<p>[1] On {{event("mousemove")}} events, the <code>which</code> property is incorrectly always set to <code>1</code> {{bug(1048294)}}.</p>

<h2 id="See_also" name="See_also">See also</h2>

<ul>
 <li>{{ domxref("MouseEvent") }}</li>
</ul>
Revert to this revision