Difference between keypress() and keydown() events

Press any key to check the event and the keycode. Non-printing keys like Esc, Shift key , Delete key etc are not triggered by keypress() event.
keydown() event is case insensitive
keypress() event is case sensitive

Press any char key and see the difference between keycodes, keep the caps Lock in on position and check again.
keydown event details here
keypress event details here

If you are using arrow keys then you must use keydown() event as keypress() event can't sesnse arrow key events.
event.which : will display the keycode or ASCII value of the key.
Full Source code is here


$(document).ready(function() {
//// keydown() ///
$('#d1').html('Keydown Event happened, keycode: '+ event.which);
setTimeout(function() { $("#d1").html('Press any key'); }, 2000);
///////keypress() //
$('#d2').html('Keypress Event happened, keycode: '+ event.which);
setTimeout(function() { $("#d2").html('Press any key'); }, 2000);


<div id=d1 class='alert alert-primary'>keydown event details here</div>
 <div id=d2 class='alert alert-primary'>keypress event details here</div>

Event Reference
keydown events Learn which key is pressed by user


* indicates required
Subscribe to plus2net


    Post your comments , suggestion , error , requirements etc here .

    Most Popular JQuery Scripts


    Two dependant list boxes


    Calendar with Date Selection


    Data change by Slider


    Show & Hide element

    JQuery Video Tutorials

    We use cookies to improve your browsing experience. . Learn more
    HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
    ©2000-2024 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer