MouseEvent buttons property

Definition and usage

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 attribute.

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 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, that is, 3).

Possible values :

  • 1: Left mouse button
  • 2: Right mouse button
  • 4: Scroll wheel button or middle button
  • 8: Fourth mouse button (usually the 'browser back' button)
  • 16: 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

Prise en charge du navigateur

Les numéros dans le tableau indiquent la version du navigateur qui prend en charge pleinement cette propriété.

Propriétés Chrome IE Firefox Safari Opera
buttons 53.0 9.0 Supporté Non supporté Supporté

Pages associées

Manuel de référence HTML DOM :Propriété button de MouseEvent

Manuel de référence HTML DOM :Propriété which de MouseEvent