Skip to content
Related Articles

Related Articles

Javascript | MouseEvent which Property

Improve Article
Save Article
  • Last Updated : 07 Jan, 2019
Improve Article
Save Article

The mouseEvent which property is used to return a number which corresponds to the pressed mouse button when a mouse event is triggered



Return value: It returns a number indicating which mouse button is pressed:

  • For left mouse button: 1 is returned
  • For middle mouse button: 2 is returned
  • For right mouse button: 3 is returned


<!DOCTYPE html>
    <title>mouseEvent which Property</title>
<body style="text-align:center;">
    <h1 style="color:green;">
            mouseEvent which Property
    <button onmousedown="geek(event)">Click me!</button>
    <p id="p"></p>
        function geek(event) {
            if (event.which == 1) {
                document.getElementById('p').innerHTML = "Left mouse" 
                                              + " button is clicked ";
            } else if (event.which == 2) {
                document.getElementById('p').innerHTML = "Middle mouse" 
                                               + " button is clicked ";
            } else if (event.which == 3) {
                document.getElementById('p').innerHTML = "Right mouse" 
                                                + "button is clicked ";

Before Clicking the button:
After clicking left mouse button:
After clicking middle mouse button:
After clicking right mouse button:

Supported Browsers: The browser supported by which mouse event are listed below:

  • Apple Safari 1.0
  • Google Chrome 1.0
  • Firefox 1.0
  • Opera 5.0
  • Internet Explorer 9.0

My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!