Find out which mouse button that was pressed when a mouse event was triggered:
<!DOCTYPE html> <html> <body> <div onmousedown="WhichButton(event)">Click this text with one of your mouse buttons to return a number. </div>/*w ww .ja v a 2s. c o m*/ <p id="demo"></p> <script> function WhichButton(event) { document.getElementById("demo").innerHTML = "You pressed button: " + event.button; } </script> </body> </html>
The button property returns a number that indicates which mouse button was pressed when a mouse event was triggered.
This property is mostly used together with the onmousedown event.
This property is read-only.
Possible values: