Easy Tutorial
❮ Jq Sel Attribute Prop Jquery Fx Interval ❯

jQuery keypress() Method

jQuery Event Methods

Example

Calculate the number of key presses in an <input> field:

$("input").keypress(function(){
    $("span").text(i+=1);
});

Definition and Usage

The sequence of events related to the keypress event:

The keypress() method triggers the keypress event, or specifies a function to run when a keypress event occurs.

The keypress event is similar to the keydown event. This event occurs when a button is pressed down.

However, the keypress event does not trigger for all keys (such as ALT, CTRL, SHIFT, ESC). Use the keydown() method to check these keys.


Syntax

Trigger the keypress event for the selected elements:

Attach a function to the keypress event:

Parameter Description
function Optional. Specifies the function to run when the keypress event is triggered.

jQuery Event Methods

❮ Jq Sel Attribute Prop Jquery Fx Interval ❯