{{APIRef}}
The MouseEvent.which
read-only property indicates which button was pressed on the mouse to trigger the event.
Syntax
var buttonPressed = instanceOfMouseEvent.which
Return value
A number representing a given button:
0
: No button1
: Left button2
: 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
Specification | Status | Comment |
---|---|---|
{{SpecName('DOM3 Events','#events-mouseevents','MouseEvent.which')}} | {{Spec2('DOM3 Events')}} | No change from {{SpecName('DOM2 Events')}} |
{{SpecName('DOM2 Events','#Events-MouseEvent','MouseEvent.which')}} | {{Spec2('DOM2 Events')}} | Initial definition. |
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") }}