The MouseEvent.buttons
read-only property indicates which buttons are pressed on the mouse when the event is triggered.
Each button that can be pressed is represented by a given number (see below). If more than one button is pressed, the value of the buttons is combined to produce a new number. For example, if the right button (2
) and the wheel button (4
) are pressed, the value is equal to 2|4,
which is 6
.
Note: Do not confuse this property with the MouseEvent.button
property. The MouseEvent.buttons
property indicates the state of buttons pressed during any kind of mouse event, while the MouseEvent.button
property only guarantees the correct value for mouse events caused by pressing or releasing one or multiple buttons.
var buttonPressed = instanceOfMouseEvent.buttons
A number representing one or more buttons. For more than one button pressed, the values are combined.
0
: No button or un-initialized1
: Left button2
: Right button4
: Wheel button or middle button8
: 4th button (typically the "Browser Back" button)16
: 5th button (typically the "Browser Forward" button)Specification | Status | Comment |
---|---|---|
Document Object Model (DOM) Level 3 Events Specification The definition of 'MouseEvent.buttons' in that specification. | Working Draft | Initial definition |
Feature | Chrome | Edge | Firefox (Gecko) | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|---|
Basic support | 43 | (Yes) | (Yes)[1] | 9 | (Yes) | No support |
Feature | Android Webview | Chrome for Android | Edge | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|---|---|
Basic support | No support | No support | (Yes) | ? | ? | ? | ? |
[1] Gecko supports the buttons
attribute on Windows, Linux (GTK), and Mac OS with the following restrictions:
© 2005–2017 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/buttons