MouseEvent buttons property

Definition and Usage

button property returns a number indicating which or which mouse buttons were pressed when the mouse event was triggered.

This property is mainly used with the onmousedown event.

Tip:Due to lack of browser support, you may need to refer to button property.

Note:This property is read-only.

Example

Find out which mouse button was pressed when the mouse event was triggered:

var x = event.buttons;

Try It Yourself

Syntax

event.buttons

Technical Details

Return value:

A numeric value representing one or more mouse buttons pressed when a mouse event occurs.

If multiple buttons are pressed, these values are combined to produce a new number (for example, if the left button (1) and the right button (2) are pressed, the return value is 1+2, which is 3).

Possible values:

  • 1: The left mouse button
  • 2: The right mouse button
  • 4: The scroll wheel button or the middle button
  • 8: The fourth mouse button (usually the 'browser back' button)
  • 16: The fifth mouse button (usually the 'browser forward' button)

Note:For mice configured for left-handed use, the return value is reversed.

DOM Version: DOM Level 3 Events

Browser Support

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

Properties Chrome IE Firefox Safari Opera
buttons 53.0 9.0 Supported Not Supported Supported

Related Pages

HTML DOM Reference Manual:MouseEvent button Property

HTML DOM Reference Manual:MouseEvent which Property