jQuery keypress() with Examples

The keypress method in jQuery is used to trigger the keypress event. It occurs when a keyboard key is pressed down.


The syntax is as follows −



Let us now see an example to implement the jQuery keypress() method

 Live Demo

<!DOCTYPE html>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
   count = 0;
         $("span").text(count += 1);
         $("input").css("color", "blue");
<p>Enter username of the student:</p>
Username: <input type="text"><br><br>
Key is pressed <span> 0 </span>times.


This will produce the following output−

Now, when the key is pressed, the count of the number of keys appeared−