We're looking for a user researcher to understand the needs of developers and designers. Is this you or someone you know? Check out the post: https://mzl.la/2IGzdXS

The MouseEvent.button read-only property indicates which button was pressed on the mouse to trigger the event.

This property only guarantees to indicate which buttons are pressed during events caused by pressing or releasing one or multiple buttons. As such, it is not reliable for events such as mouseentermouseleavemouseovermouseout or mousemove.

Users may change the configuration of buttons on their pointing device so that if an event's button property is zero, it may not have been caused by the button that is physically left–most on the pointing device; however, it should behave as if the left button was clicked in the standard button layout.

Note: Do not confuse this property with the MouseEvent.buttons property, which indicates which buttons are pressed for all mouse events types.


var buttonPressed = instanceOfMouseEvent.button

Return value

A number representing a given button:

  • 0: Main button pressed, usually the left button or the un-initialized state
  • 1: Auxiliary button pressed, usually the wheel button or the middle button (if present)
  • 2: Secondary button pressed, usually the right button
  • 3: Fourth button, typically the Browser Back button
  • 4: Fifth button, typically the Browser Forward button

As noted above, buttons may be configured differently to the standard "left to right" layout. A mouse configured for left-handed use may have the button actions are reversed. Some pointing devices only have one button and use keyboard or other input mechanisms to indicate main, secondary, auxilary, etc. Others may have many buttons mapped to different functions and button values.


var whichButton = function (e) {
    // Handle different event models
    var e = e || window.event;
    var btnCode;

    if ('object' === typeof e) {
        btnCode = e.button;

        switch (btnCode) {
            case 0:
                console.log('Left button clicked.');

            case 1:
                console.log('Middle button clicked.');

            case 2:
                console.log('Right button clicked.');

                console.log('Unexpected code: ' + btnCode);

<button onmouseup="whichButton(event);" oncontextmenu="event.preventDefault();">Click with mouse...</button>


Specification Status Comment
Document Object Model (DOM) Level 3 Events Specification
The definition of 'MouseEvent.button' in that specification.
Obsolete Compared to Document Object Model (DOM) Level 2 Events Specification, the return value can be negative.
Document Object Model (DOM) Level 2 Events Specification
The definition of 'MouseEvent.button' in that specification.
Obsolete Initial definition.

Browser compatibility

We're converting our compatibility data into a machine-readable JSON format. This compatibility table still uses the old format, because we haven't yet converted the data it contains. Find out how you can help!

Feature Edge Firefox (Gecko) Chrome Internet Explorer Opera Safari
Basic support (Yes) 1.0 (1.7 or earlier) 1.0 9.0 [1] (Yes) 3.0.4
Feature Edge Firefox Mobile (Gecko) Android IE Mobile Opera Mobile Safari Mobile
Basic support (Yes) ? ? ? ? ?

[1] This convention is not followed in Internet Explorer prior to version 9: see QuirksMode for details.

See also

Document Tags and Contributors

Last updated by: Robg1,