HTML event onkeydown

From Htmlpedia
Jump to: navigation, search

Event Attribute onKeyDown

onKeyDown is an event attribute, it takes JavaScript-code as a value. The code will be executed when:

  • The user pushes down a key on their keyboard whilst the element is in focus.

Example

In this example, the user will receive a messagebox saying "You pushed down a key on your keyboard", after focusing the element then pushing down a key on their keyboard.

<div onkeydown="alert('You pushed down a key on your keyboard')">Click me then press a key on your keyboard</div>

Controversy

As this event requires the user to push down a key on the keyboard, users with impaired motor skills or no keyboard (ie. at an information kiosk) may find this difficult or impossible.

Related

onclick, ondblclick, onmousedown, onmouseup, onmouseover, onmousemove, onmouseout, onkeypress, onkeydown, onkeyup