X
HOME HTML CSS JAVASCRIPT SQL PHP JQUERY ANGULAR BOOTSTRAP XML ASP.NET MORE...
REFERENCES | EXAMPLES | FORUM | ABOUT

MouseEvent button Property

Event Object Reference Event Object

Example

Find out which mouse button that was pressed when a mouse event was triggered:

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

Try it yourself »


Definition and Usage

The button property returns a number that indicates which mouse button was pressed when a mouse event was triggered.

This property is mostly used together with the onmousedown event.

Note: This property is read-only.


Browser Support

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

Property
button Yes Yes Yes Yes 8.0


Syntax

event.button

Technical Details

Return Value: A Number, representing which mouse button that was pressed when the mouse event occured.

Possible values:
  • 0 : Left mouse button
  • 1 : Wheel button or middle button (if present)
  • 2 : Right mouse button

Note: Internet Explorer 8 and earlier has different return values:

  • 1 : Left mouse button
  • 2 : Right mouse button
  • 4 : Wheel button or middle button (if present)
Note: For a left-hand configured mouse, the return values are reversed
DOM Version: DOM Level 2 Events


Related Pages

HTML DOM reference: MouseEvent buttons Property

HTML DOM reference: MouseEvent which Property


Event Object Reference Event Object

Your suggestion:

Close [X]

Thank You For Helping Us!

Your message has been sent to W3Schools.

Close [X]
Search w3schools.com:

WEB HOSTING

UK Reseller Hosting

WEB BUILDING

Download XML Editor FREE Website BUILDER Free HTML5 Templates

SHARE THIS PAGE

facebook