onkeydown Event
Clash Royale CLAN TAG#URR8PPP
<!--
main_leaderboard, all: [728,90][970,90][320,50][468,60]-->
onkeydown Event
❮ DOM Events
❮ KeyboardEvent
Example
Execute a JavaScript when a user is pressing a key:
<input type="text" onkeydown="myFunction()">
Try it Yourself »
More "Try it Yourself" examples below.
Definition and Usage
The onkeydown event occurs when the user is pressing a key (on the keyboard).
Tip: The order of events related to the onkeydown event:
- onkeydown
- onkeypress
- onkeyup
Browser Support
Event | |||||
---|---|---|---|---|---|
onkeydown | Yes | Yes | Yes | Yes | Yes |
<!--
mid_content, all: [300,250][336,280][728,90][970,250][970,90][320,50][468,60]-->
Syntax
In HTML:
<element onkeydown="myScript">
Try it Yourself »
In JavaScript:
object.onkeydown = function()myScript;
Try it Yourself »
In JavaScript, using the addEventListener() method:
object.addEventListener("keydown", myScript);
Try it Yourself »
Note: The addEventListener() method is not supported in Internet Explorer 8 and earlier versions.
Technical Details
Bubbles: | Yes |
---|---|
Cancelable: | Yes |
Event type: | KeyboardEvent |
Supported HTML tags: | All HTML elements, EXCEPT: <base>, <bdo>, <br>, <head>, <html>, <iframe>, <meta>, <param>, <script>, <style>, and <title> |
DOM Version: | Level 2 Events |
More Examples
Example
Using "onkeydown" together with the "onkeyup" event:
<input type="text" onkeydown="keydownFunction()" onkeyup="keyupFunction()">
Try it Yourself »
❮ DOM Events
❮ KeyboardEvent