onkeydown event
Example
Execute JavaScript code when the user presses a key:
Try it »
Definition and Usage
The onkeydown event occurs when the user presses a keyboard key.
Tip: The order of events associated with the onkeydown event:
- onkeydown
- onkeypress
- onkeyup
Syntax
In HTML:
<
element
onkeydown="
SomeJavaScriptCode
">In JavaScript:
object
.onkeydown=function(){
SomeJavaScriptCode
};
| Parameters | Description |
|---|---|
| SomeJavaScriptCode | Required. Specifies the JavaScript to be executed when the event occurs. |
Browser support





All major browsers support the onkeydown event
HTML tags that support this event:
The onkeydown attribute can be used on all HTML elements, except:
, , ,
Event Object