JQuery Keydown, Keypress and Keyup Event

Difference between JQuery Keydown, Keypress and Keyup Event
  • First Keydown Event occurs (Triggers as soon as key is press)
  • Second Keypress Event occurs (Triggers when key character is typed)
  • Third Keyup Event occurs (Triggers when key is up, after it is been pressed)
$(document).ready(function () {
        $("#txtInput").keypress(function (event) {
                if (event.which == 64) {
                    alert("You have pressed @ sign");
                }
                else if (event.which == 35) {
                    alert("You have pressed # sign");
                }
                else if (event.which == 36) {
                    alert("You have pressed $ sign");
                }
                else if (event.which == 42) {
                    alert("You have pressed * sign");
                }
                else if (event.which >= 65 && event.which <= 90) {
                    alert("You have pressed uppercase alphabet character");
                }
                else if (event.which >= 97 && event.which <= 122) {
                    alert("You have pressed lowercase alphabet character");
                }
       });
});
<input id="txtInput" type="text" />
Demo / Download
JQuery Keydown, Keypress and Keyup Event JQuery Keydown, Keypress and Keyup Event Reviewed by Bhaumik Patel on 8:19 PM Rating: 5