jQuery > Events

Keypress event in jQuery

How to attach keypress event to a html element in jQuery?

To attach keypress event to a html element, keypress()method can be used.

        $("#txtKeyPress").keypress(function () {
            $("#div3").append(" | key PRESS event fired");

In the above code when user press the key in the “txtKeyPress” textbox, “ | key PRESS event fired” text will be appended in the “div3” element.


If keyDown and keyPress both events are used for a single control, keyDown event fires first and then keyPress event fires. To know about keyDown event, click here.

 Views: 991 | Post Order: 74

Write for us