How to use jQuery keydown with example

When jQuery keydown event occurs?

The keydown event is triggered when a key is pressed down from the keyboard. The keydown() method will be used to perform any action or run a function as keypress event occurs in your web document.

Keydown event is quite similar to keypress event, however, there are differences between the two – for example pressing a few keys will trigger only keydown event like ALT, CTRL, ESC etc. keypress event will not be triggered for those keys.

Also, the keypress event returns different values for lowercase and uppercase letters, whereas the keyup and keydown return same.

Syntax of keydown jQuery method

$(selector).keydown(function)

Where function is optional, to execute as keydown event occurs.

Running example of keydown event

The example below shows when a key is pressed down and the keydown event occurs, the keydown() method will capture the event and throw an alert with ASCII value of the pressed key.

jQuery keydown

Experience this example online



Related : keypress() event | keyup() event


Was this article helpful?

Related Articles

Leave A Comment?