jQuery event.which Property

Introduction

Return which keyboard key was pressed:

View in separate window

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

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

<p>you type in the field above.</p>
<div />

</body>
</html>

The event.which property returns which keyboard key or mouse button was pressed.

event.which
Parameter Optional Description
event Required. The event parameter from the event binding function



PreviousNext

Related