jQuery keydown is one of the keyboard event methods. Other jQuery keyboard event methods are keyup and keypress.

jQuery keydown

jQuery keydown method triggers when you first press a key on the keyboard and hold it. You can attach functions to execute when this event occurs.

jQuery keydown method syntax

  1. keydown(): This jQuery keydown method is used without any arguments.
  2. keydown(handler): This jQuery keydown method attaches a function to be executed when the keydown event is fired.

jQuery keydown example

Following example demonstrates the use of jQuery keydown method.

jquery-keydown.html

In above example, when the key is pressed and hold, keydown() method is triggered which in turn executes the function that changes the background colour to green.

Below screencast shows above jQuery keydown example in action.

jquery keydown event

jQuery keydown demo

By admin

Leave a Reply