Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • keypress, keydown, keyup events in jQuery

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 225
    Comment on it

    Hello readers,
    Today we will discuss about keypress, keydown, keyup events in jQuery. These events fires when user pressed any key.


    Lets have a look all three events:

     

    • keypress: This is a special event and works when any key pressed. This event attached to any element. keypress event is not fired for ALT, CTRL, SHIFT, ESC keys.

    For example:

    <input type="text">
    
    $("input").keypress(function(){
        alert('keypress event fired');
    })
    

     

    • keydown: This event fires when any key pressed down on keyboard. From the above definition of keypress and keydown they both looks same but they are slightly different. They both works on key pressed on keyboard but keydown fires when user depressed the key and repeats while the user keeps the key depressed. On the other hand keydown event is works on ALT, CTRL, SHIFT, ESC keys.

    For Example:

    <input type="text">
    <p id="count"></p>
    
    
    var i=0;
    $("input").keydown(function(){
      i++;
      $("#count").html(i);
    })

     

    • keyup: This event fires when you release a key on keyboard.
    $("input").keyup(function(){
        alert("keyup event fired");
    });

     

    This is the brief introduction of the three events keyup, keydown, keypress. Hope this will help you :)

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: