Skip to content

Instantly share code, notes, and snippets.

@condor-bird
Created April 4, 2020 08:43
Show Gist options
  • Save condor-bird/d24fa9e33ed6804a13d670be63bb01e7 to your computer and use it in GitHub Desktop.
Save condor-bird/d24fa9e33ed6804a13d670be63bb01e7 to your computer and use it in GitHub Desktop.
Is there a JavaScript DOM change listener?
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
//...
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment