onKeyPress( )

Adds an event handler that runs when the cursor is inside the input element and a key is pressed.

A text input receives a keyPress event when a user presses a key on the keyboard while the cursor is inside the input element. A keyPress event is fired for printable and non-printable characters.

You can also define an event handler using the Properties and Events panel.


  • Some browsers do not issue a key press event for certain keys, such as arrow keys or the shift key.

  • When you retrieve the value from the target property of a KeyboardEvent, you get the value of the target element before the key was pressed.

Method Declaration
Method Parameters

eventHandler(): void The name of the function or the function expression to run when a key is pressed.

Return Type:Element
Was this helpful?