MouseEvent button Property

Definition and Usage

The button property returns a number indicating which mouse button was pressed when the mouse event was triggered.

This property is mainly used with the onmousedown event.

Note:This property is read-only.

Example

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

alert("You pressed button: " + event.button)

Try It Yourself

Syntax

event.button

Technical Details

Return value:

Numeric values representing the mouse button pressed when the mouse event occurs.

Possible values:

  • 0: Left mouse button
  • 1: Scroll wheel button or middle button (if any)
  • 2: Right mouse button

Note:Internet Explorer 8 and earlier versions have different return values:

  • 1: Left mouse button
  • 2: Right mouse button
  • 4: Scroll wheel button or middle button (if any)

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

DOM Version: DOM Level 2 Events

Browser Support

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

Properties Chrome IE Firefox Safari Opera
button Support Support Support Support 8.0

Related Pages

HTML DOM Reference Manual:MouseEvent buttons Property

HTML DOM Reference Manual:MouseEvent which Property