jQuery event.which property


The event.which property in jQuery is used to return which keyboard key or mouse button was pressed for the event.

Syntax

The syntax is as follows −

event.which

Example

Let us now see an example to implement the jQuery event.which property −

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script>
   $(document).ready(function(){
      $("input").keydown(function(event){
         $("div").html("Which key pressed? = " + event.which);
      });
   });
</script>
</head>
<body>
<h2>Student Details</h2>
Student Name: <input type="text"><br>
Student Address: <input type="text">
<p><strong>Note:</strong> The key pressed in the any of the above input would be visible below.</p>
<div />
</body>
</html>

Output

This will produce the following output −

Let us now enter a value and press a key in the input −

Updated on: 12-Nov-2019

144 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements