HTML | DOM MouseEvent buttons Property
The buttons property of mouse event is used to return a number. The number indicates which mouse button or mouse buttons were pressed when a mouse event was triggered.
This property is usually used along with the onmousedown event. This property is read-only.
Due to lack of browser support, you may want to look at the button property instead.
Syntax:
event.buttons
Return Value:
It returns a number which represents one or more mouse buttons that were pressed. If more than one button is pressed, like the left button (1) and the right button (2) then it returns 3(1+2).
Possible values:
- 1: Left mouse button
- 2: Right mouse button
- 4: Wheel button or middle button
- 8: Fourth mouse button or the “Browser Back” button
- 16: Fifth mouse button or the “Browser Forward” button
Example:
<!DOCTYPE html> <html> <head> <title> HTML DOM MouseEvent buttons Property </title> </head> <body> <center> <h1 style="color:green">GeeksforGeeks</h1> <div onmousedown="WhichButton(event)"> <h2>HTML DOM MouseEvent buttons Property</h2> </div> <h2>You pressed button: <span id="demo"></span></h2> </center> <script> function WhichButton(event) { var x = event.buttons; document.getElementById("demo").innerHTML = x; } </script> </body> </html> |
Output:
Before:

After:

Supported Browsers: The browsers supported by MouseEvent buttons Property are listed below:
- Google Chrome 53.0
- Internet Explorer 9.0
- Firefox
- Opera
Recommended Posts:
- HTML | DOM MouseEvent clientX Property
- HTML | DOM MouseEvent clientY Property
- HTML | DOM MouseEvent screenY Property
- HTML | DOM MouseEvent relatedTarget Property
- HTML | DOM MouseEvent offsetX Property
- HTML | DOM MouseEvent offsetY Property
- HTML | DOM MouseEvent pageY Property
- HTML | DOM MouseEvent pageX Property
- HTML | DOM MouseEvent screenX Property
- Javascript | MouseEvent which Property
- Javascript | MouseEvent ctrlKey Property
- JavaScript | MouseEvent shiftKey Property
- Javascript | MouseEvent altKey Property
- JavaScript | MouseEvent Button Property
- HTML | DOM MouseEvent
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



