jQuery keyboard Events

Last Updated Jul 21, 2015, 12:00:06 PM





jQuery Keyboard Events

keyboard events are focused on the user keyboard actions while interacting with the web. It will make sure what action should be performed when a specific key on the keyboard is pressed, what should be performed when the user pressed down arrow key on the keyboard, what action should be performed when the user press the up arrow on the keyboard etc...

jQuery provides many keyboard methods. Let us see each of those jquery keyboard events in detail

jQuery keydown() Event

The jQuery keydown() method triggers the keydown event, or attaches a function to run when a keydown event occurs.

Syntax

jQuery keydown() method behaviour can also be performed by .on( "keydown", handler ) and trigger( "keydown" ). Basically keydown() event is fired when the user press down arrow key on the keyboard.

Example
Try It Now

jQuery keypress() Event

jQuery keypress() event is used to bind an event handler to javascript “keypress” event when the user performes a keypress on the keyboard

Syntax

jQuery keypress() method behaviour can also be performed by on( "keypress", handler ) and jQuery trigger( "keypress" ). Basically jQuery keydown() event will be fired when browser register any keyboard event.

Here is an example on how to use jquery keypress() method.

Example

In this example, the no.of times the event occurs will be shown as a result when user try to press the key on the keyboard.

Output
jquery keypress() event

Try It Now

jQuery keyup() Event Method

The jQuery keyup() method triggers the keyup event, or attaches a function to run when a keyup event occurs

Syntax

jQuery keyup() method behaviour can also be performed by .on( "keyup", handler ) and jquery trigger( "keyup" ).

Example

In the above example, it will change its color of the text box if you press the keyup and keydown arrows.

Try It Now

Other Advanced jQuery Events you might want to learn
jQuery Complete Events Reference

jQuery Events

jQuery Document Events

jQuery Keyboard Events

jQuery Mouse Events


Sources and Credits

The content and methods in the tutorial has been referred and updated with jQuery API and The jQuery Foundation

Last Updated Jul 21, 2015, 12:00:06 PM