Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

onkeydown event

onkeydown event

Event Object Reference Event Object

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:

  1. onkeydown
  2. onkeypress
  3. 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

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support the onkeydown event


HTML tags that support this event:

The onkeydown attribute can be used on all HTML elements, except:, ,
, , ,