How to detect and change the content/style of a div using jQuery ? Last Updated : 05 Nov, 2019 Comments Improve Suggest changes Like Article Like Report 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.7. Syntax: $(selector).on(event, childSelector, data, function, map) Example 1: This example uses jQuery on() method to change the text of the <div> element. HTML <!DOCTYPE html> <html> <head> <title> How to detect and change the content of a div using JQuery ? </title> <script src= "https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"> </script> <style> #div1 { font-size: 35px; color:green; text-align:center; } </style> <script> $(document).ready(function(){ $("div").on("click", function(){ document.getElementById("div1").innerHTML = "A computer science portal for geeks"; }); }); </script> </head> <body> <div id="div1">GeeksforGeeks!</div> </body> </html> Output: Before clicking the div element: After clicking the div element: Example 2: This example uses jQuery on() method to change the style of a <div> element. javascript <!DOCTYPE html> <html> <head> <title> How to detect and change the style of a div using JQuery? </title> <script src= "https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"> </script> <style> #div1 { font-size: 35px; color:green; text-align:center; } </style> <script> $(document).ready(function(){ $("div").on("click", function(){ document.getElementById("div1").style.color = "white"; document.getElementById("div1").style.backgroundColor = "green"; }); }); </script> </head> <body> <div id="div1">Welcome to GeeksforGeeks!!!</div> </body> </html> Output: Before clicking the div element: After clicking the div element: Comment More infoAdvertise with us Next Article How to detect and change the content/style of a div using jQuery ? C chaitanyashah707 Follow Improve Article Tags : Web Technologies JQuery jQuery-Selectors jQuery-Misc Similar Reads 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 call a function when content of a div changes using jQuery ? 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 oc 2 min read JQuery | Detect a textbox content is changed or not In order to detect the text content of input is changed or not, We are using the .on() method of JQuery. .on() This is a built-in method provided by jQuery and is used to attach event handlers for the selected elements and their child elements. Syntax: $(selector).on(event, childSel, data, fun, map) 2 min read How to get the outer html of an element using jQuery ? Sometimes, there is a need to get the entire HTML element by its id and not merely its contents, for doing so, we shall use the HTML DOM outerHTML Property to get the outer HTML of HTML element. Syntax: document.getElementById("your-element-id").outerHTML) You can use a variable and initialize it to 2 min read Like