Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

How to run the code on keypress event using jQuery ?

  • Last Updated : 30 Sep, 2021

In this article, we will see how to run the code snippet on the keypress event using jQuery. The keypress event is triggered when the keyboard button is pressed by the user.


Attention reader! Don’t stop learning now. Get hold of all the important HTML concepts with the Web Design for Beginners | HTML  course.


In the below example, we are creating a textarea element and when the user starts pressing a key to writing some content on textarea, the keypress event is triggered. When this event is triggered, the CSS styles are added to the element. 



<!DOCTYPE html>
          How to run the code on keypress 
          event using jQuery ?
    <script src=
        $(document).ready(function () {
            $("textarea").keypress(function () {
                    background: "green",
                    color: "white",
        <h1 style="color: green">GeeksforGeeks</h1>
          How to run the code on keypress 
          event using jQuery ?
        <textarea rows="5" cols="30"></textarea>


My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!