Created
November 9, 2017 15:39
-
-
Save jacobovidal/10bf64a9f6f3c85cca745441ad8b126c to your computer and use it in GitHub Desktop.
Mutation observer example in JavaScript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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