event.which

JavaScript 1.2+ Nav4+ Syntax

							event.which

Description

The which property of the Event object refers to which key or mouse button was pressed or clicked. The value returned for mouse events is a numeric value 1, 2, or 3, representing the left, middle, and right mouse buttons, respectively. The value returned for keyboard events is a character representation for the key that was pressed.

Example

Listing 7.215 shows how the which property can be used to determine which mouse button was pressed. When the user clicks the radio button, an alert box is shown informing you of the corresponding number for the mouse button clicked.

Listing 7.215 Accessing the which Property of Event Object
 <html> <head> <title>Using the which property ...

Get Pure JavaScript now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.