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 values:

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 left-handed mouse configuration, the return value is reversed.

DOM Version: DOM Level 2 Events

Mwamadharani wa kifungu

Inaonekana kwenye tabia ya kina ya tabia inaonekana kwenye kina cha kwanza cha kusimamia tabia hii.

Mafano ya mafano Chrome IE Firefox Safari Opera
button Mwamadharani Mwamadharani Mwamadharani Mwamadharani 8.0

Vipindi vya vingine

Makala ya HTML DOM ya DOM:属性 ya MouseEvent buttons

Makala ya HTML DOM ya DOM:属性 ya MouseEvent which