Is it possible to detect if the content of a paragraph has been changed in JQuery ?
I tried the below code.
<p id="test">Text</p>
<button id="submit1">change</button>
-
$(document).on("click", "#submit1", function () {
var d = new Date();
var time = d.getHours() + ":" + d.getMinutes() + ":" + d.getSeconds();
$("#test").text(time);
});
$(document).on("change", "#test", function () {
alert("Paragraph changed");
});
JSFiddle : http://jsfiddle.net/nnbqye55/
I guess I am missing something obvious.
To change text inside an element using jQuery, use the text () method. You can try to run the following code to replace text inside an element:
With the help of jQuery, select all the paragraph elements. Apply some CSS property to the <p> element to see the change. You may use the .css () method to apply CSS property.
Using the html() Method to Change Text on Click The jQuery html()method is very useful when it comes to manipulating web pages. We can use the jQuery html()method to change the html and text of an element. Let’s say we have the following code and we want to add html content to the span inside of our paragraph.
Of course, you can use this same method to replace any text for an empty string removing the searched string from our text. We can replace the whole text of any element on our page by using the text function of jQuery. It's even more simple yet: $("#element").text("What's up!");
You can use 'DOMSubtreeModified' to check the dom changes on html tag elements. See the support for this event across browsers.
http://jsfiddle.net/nnbqye55/7/
$(document).on("DOMSubtreeModified", "#test", function () {
alert("Paragraph changed");
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With