event.which
: will display the keycode or ASCII value of the key. <script>
$(document).ready(function() {
//// keydown() ///
$(document).keydown(function(){
$('#d1').html('Keydown Event happened, keycode: '+ event.which);
$("#d1").show();
setTimeout(function() { $("#d1").html('Press any key'); }, 2000);
});
///////keypress() //
$(document).keypress(function(){
$('#d2').html('Keypress Event happened, keycode: '+ event.which);
$("#d2").show();
setTimeout(function() { $("#d2").html('Press any key'); }, 2000);
});
///
});
</script>
<div id=d1 class='alert alert-primary'>keydown event details here</div>
<div id=d2 class='alert alert-primary'>keypress event details here</div>
Most Popular JQuery Scripts | |
1 | Two dependant list boxes |
2 | Calendar with Date Selection |
3 | Data change by Slider |
4 | Show & Hide element |