ExampleChange the background color of an input field each time a key is pressed:
Try it yourself » |
A key press has two parts: 1. The key is pressed down. 2. The key is released.
The keydown event occurs when a keyboard key is pressed down.
The keydown() method triggers the keydown event, or specifies a function to run when a keydown event occurs.
Tip: Use the event.which property to return which key was pressed.
Trigger the keydown event for the selected elements.
|
Try it yourself » |
Specifies a function to run when the keydown event occurs for the selected elements.
|
Try it yourself » |
Parameter | Description |
---|---|
function | Optional. Specifies the function to run when the keydown event occurs |
![]() |
Try it Yourself - Examples |
Determine which key was pressed
How to determine which key was pressed.