location event attribute
Example
Get the location of the key:
var
x = event.location;
x The output is:
0
Try it »
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:
Indicates a key that is neither the leftmost nor the rightmost, nor a number on the numeric keypad (this value covers almost all keys, such as "A", "U", "SPACE" or "5")
1. DOM_KEY_LOCATION_LEFT:
Left key (if the left "CTRL" key or the left "ALT" key)
2. DOM_KEY_LOCATION_RIGHT:
Right key (if the right "CTRL" key or the left "ALT" key)
3. DOM_KEY_LOCATION_NUMPAD:
Numeric key (on the right side of a standard keyboard)
Note: The location property can be used in the event, but cannot be used in onkeydown and onkeyup the event, but cannot be used in onkeypressevents.
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
event
.location
Technical Details
| Return value: | A number representing the position of the key on the keyboard or device.
The 4 numbers can be represented by constants:
0. DOM_KEY_LOCATION_STANDARD
- DOM_KEY_LOCATION_LEFT
2. DOM_KEY_LOCATION_RIGHT
3. DOM_KEY_LOCATION_NUMPAD | | --- | --- | | DOM version: | DOM Level 3 Events |
Event Object