MouseEvent button Property
Example
Which mouse button was pressed?
let text = "You pressed button: " + event.button;
Try it Yourself »
Description
The button
property returns which mouse button is pressed when a mouse event
occurs.
The button
property is mostly used with the
onmousedown
event.
The button
property is read-only.
Syntax
event.button
Technical Details
Return Value: | A Number. Which mouse button that was pressed: 0 : Left button 1 : Wheel or middle button (if present) 2 : Right button For a left-hand configured mouse, the values are reversed. |
---|---|
DOM Version: | DOM Level 2 Events |
Browser Support
event.button
is a DOM Level 2 (2001) feature.
It is fully supported in all browsers:
Chrome | Edge | Firefox | Safari | Opera | IE |
Yes | Yes | Yes | Yes | Yes | 9-11 |
Copyright 1999-2023 by Refsnes Data. All Rights Reserved.