Your Search Results

    MouseEvent.buttons

    Summary

    The buttons property indicates which buttons were pressed on the mouse to trigger the event.

    Each button that can be pressed is representd by a given number (see below). If more than one button is pressed, the value of the buttons is combined to produce a new number. For example, if the right button (2) and the wheel button (4) are pressed, the value is equal to 2|4, which is 6.

    Warning: Beware to not mix this up with the DOM2 MouseEvent.button property.

    Syntax

    var buttonPressed = instanceOfMouseEvent.buttons
    

    Value

    A number representing one or more buttons. For more than one button pressed, the values are combined.

    • : Left button
    • : Right button
    • : Wheel button
    • : 4th button (typically the "Browser Back" button)
    • 16 : 5th button (typically the "Browser Forward" button)

    Specifications

    Specification Status Comment
    Document Object Model (DOM) Level 2 Events Specification Recommendation  
    Document Object Model (DOM) Level 3 Events Specification Working Draft  
    UI Events Working Draft Extend DOM3
    Pointer Lock Working Draft Extend the MouseEvent interface

    Browser compatibility

    Feature Firefox (Gecko) Chrome Internet Explorer Opera Safari
    Basic support (Yes) (Yes) (Yes) (Yes) (Yes)
    movementX
    movementY
    (Yes) moz (Yes) webkit ? ? ?
    buttons (Yes) Not supported ? ? ?
    Feature Firefox Mobile (Gecko) Android IE Mobile Opera Mobile Safari Mobile
    Basic support ? ? ? ? ?

    Gecko notes

    Gecko supports the buttons attribute on Windows, Linux (GTK), and Mac with the following restrictions:

    • On Windows, if you install a mouse driver, and its utility software allows you to customize button actions (e.g., IntelliPoint and SetPoint), the middle (wheel) button, the 4th button, and the 5th button might not be set, even when they are pressed.
    • On Linux (GTK), the 4th button and the 5th button are not supported. In addition, a mouseup event always has the releasing button information in this attribute value.
    • On Mac OS X 10.5, the buttons attribute always returns 0 because there is no platform API for implementing this feature.

    See also

    Document Tags and Contributors

    Contributors to this page: amycb, brunoais, kscarfone, zastrowm, Jeremie
    Last updated by: brunoais,