Code has been added to clipboard!

Learn to Use jQuery .keypress() to Track Keyboard Actions

Reading time 1 min
Published Jul 3, 2019
Updated Sep 30, 2019

jQuery keypress: Main Tips

  • The method .keypress() attaches an event handler for when a key is pressed, or triggers the keypress event.
  • The keypress event is similar to the keydown. However, keypress is not invoked by non-printing keys.

Usage of. keypress()

The jQuery .keypress() applies an event handler for the keypress event. It can trigger the event as well. The keypress event occurs when a key on the keyboard is pressed.

In the example below, the number of times you press keyboard keys while typing into an input field is displayed:

To simply trigger the keypress event, use this syntax:

$("selector").keypress();

Follow this syntax to specify a function to be executed when the event is triggered:

$("selector").keypress(function)

Warning: the actual results from jQuery .keypress() method might depend on different platforms, browsers, and their versions.

Latest Udacity Coupon Found:

Verified STAFF PICK

75% OFF COURSES

Udacity Black Friday Offer

The best time to save on Udacity courses is now - follow this coupon to access a 75% Udacity Black Friday discount & enjoy learning at a very low cost!

Expiration date: 28/01/2021
3176 People Used
Only 97 Left
Rating
5.0