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.

 <script>
        $("#txtKeyPress").keypress(function () {
            $("#div3").append(" | key PRESS event fired");
        });
    </script>

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.

Note

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: 6536 | Post Order: 74



Write for us






Hosting Recommendations