jQuery Event : Detect changes to the html/text of a div
If you don't want use timer and check innerHTML you can try this event
$('mydiv').bind('DOMSubtreeModified', function(){ console.log('changed');});
More details and browser support datas are Here.
Attention: in newer jQuery versions bind() is deprecated, so you should use on() instead:
$('body').on('DOMSubtreeModified', 'mydiv', function(){ console.log('changed');});
Using Javascript MutationObserver
//More Details https://developer.mozilla.org/en-US/docs/Web/API/MutationObserver // select the target nodevar target = document.querySelector('mydiv')// create an observer instancevar observer = new MutationObserver(function(mutations) { console.log(target.innerText); });// configuration of the observer:var config = { attributes: true, childList: true, characterData: true };// pass in the target node, as well as the observer optionsobserver.observe(target, config);
Since $("#selector").bind()
is deprecated, you should use:
$("body").on('DOMSubtreeModified', "#selector", function() { // code here});