MouseEvent buttons Property

Event Object Reference Event Object


Find out which mouse button(s) that was pressed when a mouse event was triggered:

var x = event.buttons;
Try it yourself »

Definition and Usage

The buttons property returns a number that indicates which mouse button or mouse buttons were pressed when a mouse event was triggered.

This property is mostly used together with the onmousedown event.

Tip: Due to lack of browser support, you may want to look at the button property instead.

Note: This property is read-only.

Browser Support

The numbers in the table specify the first browser version that fully supports the property.

buttons Not supported 9.0 Yes Not supported Not supported



Technical Details

Return Value: A Number, representing one or more mouse buttons that were pressed when the mouse event occured. If more than one button is pressed, the values are combined to produce a new number (For example, if the left button (1) and the right button (2) are pressed, the returned value is 1+2, which is 3).

Possible values:
  • 1 : Left mouse button
  • 2 : Right mouse button
  • 4 : Wheel button or middle button
  • 8 : Fourth mouse button (typically the "Browser Back" button)
  • 16 : Fifth mouse button (typically the "Browser Forward" button)
Note: For a left-hand configured mouse, the return values are reversed
DOM Version: DOM Level 3 Events

Related Pages

HTML DOM reference: MouseEvent button Property

HTML DOM reference: MouseEvent which Property

Event Object Reference Event Object