locationEvent Attributes
Example
Get the position of the key:
xThe output result is:
Try it yourself »
Definition and Usage
The location property returns the position of the key on the keyboard or device.
The number can be represented by 4 constants:
0. DOM_KEY_LOCATION_STANDARD:
Represents a key that is not the leftmost or rightmost key, and not a number on the numeric keypad (this value includes almost all keys, such as "A", "U", "SPACE" or "5")
1. DOM_KEY_LOCATION_LEFT:
Left key (if the left "CTRL" key or left "ALT" key)
2. DOM_KEY_LOCATION_RIGHT:
Right key (if the right "CTRL" key or left "ALT" key)
3. DOM_KEY_LOCATION_NUMPAD:
Number key (on the right side of a standard keyboard)
Note:The location property can be used foronkeydownandonkeyupevents, but cannot be used foronkeypressevents.
Note:This property is read-only.
Browser Support
The numbers in the table indicate the version number of the first browser that supports this property.
| Property | |||||
|---|---|---|---|---|---|
| location | Yes | 9.0 | 15.0 | Not supported | Yes |
Syntax
Technical Details
| Return Value: | A number representing the position of the key on the keyboard or device. 4 numbers can be represented by constants: 0. DOM_KEY_LOCATION_STANDARD |
|---|---|
| DOM Version: | DOM Level 3 Events |
Other Extensions
Event Object