jQuery keydown() show key code

Introduction

When you type in the field above, the div element below will display the key number.

View in separate window

<!DOCTYPE html>
<html>
<head>
<script 
 src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js">
</script>/*  w  w  w.  jav  a  2s  .  c o m*/
<script>
$(document).ready(function(){
  $("input").keydown(function(event){
    $("div").html("Key: " + event.which);
  });
});
</script>
</head>
<body>

Enter your name: <input type="text">
<div />

</body>
</html>



PreviousNext

Related