THE INDIA LARGEST WEB DEVELOPER SITE
HTMLCSSJAVASCRIPTSQLPHPBOOTSTRAPJQUERYANGULARXML
 

HTML onkeydown Event Attribute

HTML Event Attributes HTML Event Attributes

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 attribute fires when the user is pressing a key (on the keyboard).

Tip: The order of events related to the onkeydown event:

  1. onkeydown
  2. onkeypress
  3. onkeyup

Browser Support

Event Attribute
onkeydown Yes Yes Yes Yes Yes

Differences Between HTML 4.01 and HTML5

None.


Syntax

<element onkeydown="script">

Attribute Values

Value Description
script The script to be run on onkeydown

Technical Details

Supported HTML tags: All HTML elements, EXCEPT: <base>, <bdo>, <br>, <head>, <html>, <iframe>, <meta>, <param>, <script>, <style>, and <title>

Examples

More Examples

Example

Using "onkeydown" together with the "onkeyup" attribute:

<input type="text" onkeydown="keydownFunction()" onkeyup="keyupFunction()">
Try it yourself »

Related Pages

HTML DOM reference: onkeydown event


HTML Event Attributes HTML Event Attributes