TheMouseEvent.buttons
read-only property indicates which buttons are pressed on the mouse (or other input device) 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 secondary (2
) and auxilary (4
) buttons are pressed together, the value is 6
(i.e. 2 + 4
).
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 simultaneously, the values are combined (e.g. 3 is primary + secondary).
0
: No button or un-initialized1
: Primary button (usually left)2
: Secondary button (usually right)4
: Auxilary button (usually middle or mouse wheel button)8
: 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. | Obsolete | Initial definition |
Desktop | ||||||
---|---|---|---|---|---|---|
Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | |
Basic support | 43 | Yes | Yes
|
9 | Yes | No |
Mobile | |||||||
---|---|---|---|---|---|---|---|
Android webview | Chrome for Android | Edge Mobile | Firefox for Android | Opera for Android | iOS Safari | Samsung Internet | |
Basic support | No | No | Yes | ? | ? | No | ? |
Firefox supports the buttons
attribute on Windows, Linux (GTK), and Mac OS with the following restrictions:
© 2005–2018 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