Latest web development tutorials
 

MouseEvent which Property

< Event Object

Example

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

alert("You pressed button: " + event.which)
Try it Yourself »

Definition and Usage

The which 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: The values returned by this property are the same as those returned by the button property plus one.

Note: This property is read-only.


Browser Support

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

Property
which 1.0 9.0 1.0 1.0 5.0

Syntax

event.which

Technical Details

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

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

Related Pages

HTML DOM reference: MouseEvent button Property

HTML DOM reference: MouseEvent buttons Property


< Event Object