Skip to content

Instantly share code, notes, and snippets.

@jacobovidal
Created November 9, 2017 15:39
Show Gist options
  • Save jacobovidal/10bf64a9f6f3c85cca745441ad8b126c to your computer and use it in GitHub Desktop.
Save jacobovidal/10bf64a9f6f3c85cca745441ad8b126c to your computer and use it in GitHub Desktop.
Mutation observer example in JavaScript
if (window.MutationObserver || window.WebKitMutationObserver) {
var observer = new MutationObserver(function (mutations, observer) {
// Do something after node has changed
console.log('#div has changed')
});
// Configuration of the observer
var config = {
subtree: true,
attributes: true
}
// The node to be monitored
var target = document.querySelector('#div');
// Start observing
observer.observe(target, config);
// Stop observing (optional)
observer.disconnect();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment