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:

Numeric values representing one or more mouse buttons pressed during a mouse event.

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: Left mouse button
  • 2: Right mouse button
  • 4: Scroll wheel button or 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

Browserunderstøttelse

Tal i tabellen angiver den første browserversion, der fuldt ud understøtter egenskaben.

Egenskaber Chrome IE Firefox Safari Opera
knapper 53.0 9.0 Understøttet Ikke understøttet Understøttet

Relaterede sider

HTML DOM referencehåndbog:MouseEvent button egenskab

HTML DOM referencehåndbog:MouseEvent which egenskab