Easy Tutorial
❮ Sel Input Jquery Fade ❯

jQuery keydown() Method

jQuery Event Methods

Example

Set the background color of an <input> field when a keyboard key is pressed:

$("input").keydown(function(){
    $("input").css("background-color","yellow");
});

Definition and Usage

The sequence of events related to the keydown event:

-keypress - A key is pressed

-keyup - A key is released

The keydown event occurs when a keyboard key is pressed.

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 keyboard key was pressed.


Syntax

Trigger the keydown event for the selected elements:

Attach a function to the keydown event:

Parameter Description
function Optional. Specifies the function to run when the keydown event is triggered.

More Examples

Determine which key was pressed


jQuery Event Methods

❮ Sel Input Jquery Fade ❯