onKeyPress( )

Adds an event handler that runs when a keyboard key is pressed while the container or one of its child elements is focused.

A container receives a keyPress event when a site visitor presses a keyboard key on the container or any of its child elements. A keyboard event is triggered for any child elements inside the container that support onKeyPress().

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 don't 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
This method does not take any parameters
Return Type:Element
Was this helpful?