Execute a JavaScript when a user is pressing a key:
More "Try it Yourself" examples below.
The onkeydown attribute fires when the user is pressing a key (on the keyboard).
Tip: The order of events related to the onkeydown event:
Event Attribute | |||||
---|---|---|---|---|---|
onkeydown | Yes | Yes | Yes | Yes | Yes |
None.
Value | Description |
---|---|
script | The script to be run on onkeydown |
Supported HTML tags: | All HTML elements, EXCEPT: <base>, <bdo>, <br>, <head>, <html>, <iframe>, <meta>, <param>, <script>, <style>, and <title> |
---|
Using "onkeydown" together with the "onkeyup" attribute:
HTML DOM reference: onkeydown event