Is it possible to detect if the content of a paragraph has been changed in JQuery ?
I tried the below code.
Text
The approved answer didn't work for me so here is my revised and working example for anyone looking.
function getNode(){
//Store the test paragraph node
var test = $('#test');
if(!test){
// The node we need may not exist yet
// Wait 500ms and try again
window.setTimeout(getNode, 500);
return;
}
//Function to change the paragraph
var changeParagraph = function () {
var d = new Date();
var time = d.getHours() + ":" + d.getMinutes() + ":" + d.getSeconds();
test.text(time);
};
//Bind the paragraph changing event
$('#submit1').on('click', changeParagraph);
//Observe the paragraph
this.observer = new MutationObserver(changeParagraph);
this.observer.observe(test, {characterData: true, childList: true});
});
//Delay calling our function until page loads
setTimeout(function() {
getNode();
}, 5000);