-
Tell about any changes in the DOM.
-
Javascriptjavascript_interview_questiondebuggingtips_and_tricks
-
The below script gets triggered when there is a change in the DOM,
MutationObserver = window.MutationObserver || window.WebKitMutationObserver;
var observer = new MutationObserver(function(mutations, observer) {
// fired when a mutation occurs
console.log(mutations, observer);
// ...
});
// define what element should be observed by the observer
// and what types of mutations trigger the callback
observer.observe(document, {
subtree: true,
attributes: true
//...
});- It gives output like this,
