DOM MouseEvent.button Property
The button property tells you which mouse button was pressed or released: 0 for the main button, 1 for the middle and 2 for the secondary button.
Description
The read-only button property indicates which mouse button triggered a mousedown, mouseup or similar event. The "main" and "secondary" buttons are swapped for left-handed mouse settings. The buttons property (plural) gives a bit mask of every button currently held down.
For click events, button is always 0, since click only fires for the main button. The auxclick event fires for other buttons, such as a middle-click, and contextmenu fires for the secondary button or the keyboard's menu key.
Overriding the right-click menu prevents users from using familiar browser features, such as opening links in new tabs, so only do it when you provide a genuinely useful replacement, such as in a drawing or file-management app.
Syntax
event.buttonValue
A number for the button that changed state: 0 main (usually left), 1 middle, 2 secondary (usually right), 3 back and 4 forward.
Example
Browser Support
The following information will show you the current browser support for the MouseEvent.button property. Hover over a browser icon to see the version that first introduced support for this property.
Desktop





Tablets & Mobile





