How to call a function when content of a div changes using jQuery ? Last Updated : 24 May, 2021 Comments Improve Suggest changes Like Article Like Report The task is to call a function when the content of a div is changed. You can achieve this task by using the in-built method known as .change(). In simple words whenever the field is been changed we call a function that will throw a pop-up. .change(): This method will only trigger when some change occurs in the element or field. It accepts an optional function as an argument that will perform some kind of work. Syntax: $(selector).change(function()) selector: It will select an element on which we have to perform this task. function(): It is an optional argument that will specify the function to run when the change event occurs for the selected elements. Approach 1: In this approach, we are going to implement its execution without taking any parameter such as function. First, create an input box with some value and onChange attribute.Create a button and map it to the script where you have written the change method without any argument. Explanation: When you click a button trigger change event of the input field occurs and pop-up window will appear and display whatever present in the input field. Example 1: HTML <!DOCTYPE html> <html> <head> <script src= "https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"> </script> <script> $(document).ready(function(){ $("button").click(function(){ $("input").change(); }); }); </script> </head> <body> <p> <h1> Press enter to see the pop-up. which says whatever written in the input field </h1> </p> <p>Enter anything you wish to: <input value="GeeksForGeeks" onchange="alert(this.value)" type="text"></p> <button> Trigger change event for input field </button> </body> </html> Output: Before click: After click: Approach 2: In this approach, we are going to implement its execution with the help of function as an argument in the change method. Make an input field of text type.Map input element to the change() method and write some text to show on function call. Explanation: When you enter something in the input field and press enter then the change event will run and executes the function and show the message that is written in the function. Example 2: HTML <!DOCTYPE html> <html> <head> <script src= "https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"> </script> <script> $(document).ready(function(){ $("input").change(function(){ alert("Welcome geek you have changed something."); }); }); </script> </head> <body> <input type="text"> <p><h1> Enter something and press enter to see the effect. <h1></p> </body> </html> Output: Comment More infoAdvertise with us Next Article How to call a function when content of a div changes using jQuery ? B bhaluram18 Follow Improve Article Tags : Web Technologies JQuery jQuery-Methods jQuery-Questions Similar Reads How to detect and change the content/style of a div using jQuery ? The changes to the html/text of a div can be detected using jQuery on() method. The on() is used to attach one or more event handlers for the selected elements and child elements in the DOM tree. The on() method is the replacement of the bind(), live() and delegate() method from the jQuery version 1 2 min read How to call a function automatically after waiting for some time using jQuery? In order to run a function automatically after waiting for some time, we are using the jQuery delay() method. The .delay() method in jQuery which is used to set a timer to delay the execution of the next item in the queue.Syntax: $(selector).delay(para1, para2); Approach: When the Button is clicked 2 min read How to run the code on change event using jQuery ? 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. 1 min read How to change the color of any div that is animated using jQuery ? In this article, we will learn to change the color of any HTML div that is animated using jQuery.We will be using the jQuery .animate() method to change the background colors of any element. The jQuery .animate() method is used to create smooth animations by changing the CSS properties of elements o 2 min read How to find all children with a specified class using jQuery ? There are lots of javascript libraries like - anime.js, screenfull.js, moment.js, etc. JQuery is also a part of javascript libraries. It is used to simplify the code. It is a lightweight and feature-rich library. In this article, we will learn how to find all children with a specified class of each 2 min read How to find the class of clicked element using jQuery ? In this article, we will find the class of the clicked element using jQuery. To find the class of clicked element, we use this.className property. The className property is used to set or return the value of an elementâs class attribute. Using this property, the user can change the class of an eleme 1 min read How to use jQuery library and call functions from it ? In this article, we will see how we can include the jQuery library in the code & use the different call functions. We will be adding some animation effects to see its uses. jQuery is a lightweight JavaScript library that was built to simplify complex JavaScript tasks by generalizing various conc 7 min read How to fadeOut and remove a div using jQuery ? Given a div element. The task is to remove it with a fadeOut effect using JQuery. Here are a few methods discussed. First few methods to know. jQuery text() Method: This method sets/returns the text content of the selected elements. If this method is used to return content, it provides the text cont 4 min read How to get styles of a clicked division using jQuery ? In this article, we will learn how to get the styles (width, height, text color, and background color) of a clicked division using jQuery. Approach: The css() method is used to get the CSS property values of the selected element in jQuery. We use the css() method in jQuery that takes an array of nam 2 min read How to change the checkbox value using jQuery ? The Checkboxes are used to let a user select one or more options for a limited number of choices. The :checkbox selector selects input elements with type checkbox.Syntax: $('#textboxID').val($("#checkboxID").is(':checked')); In the above syntax, basically the return value of the checked or unchecked 2 min read Like