Find out which mouse button that was pressed when a mouse event was triggered:
<!DOCTYPE html> <html> <body> <p id="demo"></p> <div onmousedown="WhichButton(event)">Click this text with one of your mouse buttons to return a number. </div>//from w ww. jav a 2s . c om <script> function WhichButton(event) { document.getElementById("demo").innerHTML = "You pressed button: " + event.which; } </script> </body> </html>
The which property returns a number telling which mouse button was pressed when a mouse event was triggered.
The values returned by this property are the same as those returned by the button property plus one.
This property is read-only.
Possible values: