JSFiddle - React, Tailwind, and code Playground
HTML
<span id="myDiv"></span>
JavaScript
// THIRD FUNCTION (changes the text)
var i = 0;
function thirdFUN(){
i++;
var popo = document.getElementById('myDiv');
popo.innerText = i;
}
setInterval(thirdFUN, 500);
//---------------------------------------------------------------
// JQUERY
/*var popo = $('#myDiv');
$('#myDiv').bind("DOMSubtreeModified",function(){
if (popo.html() == "10")
console.log('changed');
});
*/
//---------------------------------------------------------------
// PURE JS
window.onload = function(){
var popo = document.querySelector('#myDiv');
var observer = new MutationObserver(function(mutations){
mutations.forEach(function(mutation){
console.log(mutation.type); // <- It always detects changes
if (popo.innerHTML == "10"){
alert('hello');
}
});
});
var config = {characterData: true, subtree: true};
observer.observe(popo, config);
//observer.disconnect();
}