Introduction:

Here we are going to explain what is keypress() event or how to use keypress() event or why to use keypress() event with example.

Description: 

The jQuery keypress() event is executed when a keyboard button is pressed down. This event is similar to keydown() event. The keypress() method is executed or attach a function to run when a keypress() event occurs.

  • Syntax:

Trigger the keypress event for the selected elements:

 

$(selector).keypress()


  • Example of jQuery keypress() event

Let's see an example to of jQuery keypress() event.

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>jquery keypress tutorial</title>
    <script src="Scripts/jquery-1.8.2.min.js"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            $("input").keypress(function () {
                $("#content").text($(this).val());
                $("#content").css("color", "red");
            });
 
        });
    </script>
 
</head>
<body>
    Write something: <input type="text">
    <p id="content" style="margin-top:10px; width: 300px; height: 88px; color:#fff;">
 
    </p>
</body>
</html>

 

Output:



I hope it will help to you.

0 comments


Leave a comment

Make sure you enter the (*) required information where indicated. HTML code is not allowed.

Welcome to SQL Tutorials Point

Don't have an account? Click here to Create a new account, it takes less than a minute.