Get which mouse button is clicked in JavaScript

Description

The following code shows how to get which mouse button is clicked.

Example


<html>
<body>
  <form>
    This example uses the which property of the event object to determine
    which mouse button is pressed. <br>
    <br> <input type="radio"
      onClick='alert("Mouse button Number " + event.which + "was pressed.")'>
  </form><!-- www  .  j a v  a  2s.c  om-->
</body>
</html>

Click to view the demo





















Home »
  Javascript »
    Javascript Reference »




Array
Canvas Context
CSSStyleDeclaration
CSSStyleSheet
Date
Document
Event
Global
History
HTMLElement
Input Element
Location
Math
Number
String
Window