Open In App

How to run the code on change event using jQuery ?

Last Updated : 15 May, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

In this article, we will see how to run the code on change events using jQuery. The change event is used to trigger when the user changes the value of the element.

Syntax:

$(selector).change(function)

Example: In the below example, we are creating a textarea element that contains GeeksforGeeks text. When the user changes the textarea content and removes the cursor from the textarea, the change event is triggered and the styles are added to the textarea element. 

HTML




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


Output: 



Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads