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.