jQuery keypress() Method - CodingTag

jQuery keypress()


  • This jQuery function is worked when the keypress event occurs or it binds a function to run when a keypress event occurs.
  • A keypress event happens by pressing a keyboard key like keydown() method but it will not work for keys. For example: it will not work on the pressing of ALT, CTRL, SHIFT, and ESC keys.
  • There are two other events are present in jQuery that are related to keypress event.

1 keydown: This event happens when a keyboard key is on its way down.

2 keyup: This event happens when a keyboard key is released.

Related Topic:

jQuery focus
jQuery blur

jQuery keypress


$(selector).keypress() ;


If you want to trigger a function in it, the syntax will be:


Parameter description:

  • function: It represents the function to run when the keypress event is triggered. It is optional.


In this example, we return the input field value and its length after pressing a single key.

<title> jQuery Example </title>
<script type = "text/javascript"
i = 0;
$(this).css("background-color", "pink");
$(".st2").text(i += 1);


<h2> jQuery Keypress Event Example </h2>
Name: <input class="name" type="text" name="fullname"><br>
<strong class="st1"></strong><br>
Length: <strong class="st2">0</strong>


After, enter a name,

Best WordPress Hosting


Discount Coupons

Get a .COM for just $6.98

Secure Domain for a Mini Price

Leave a Reply

    Waiting for your comments