Last active
March 22, 2018 10:20
-
-
Save vldvel/5a17d906da5cee665f1f576fd25710ba to your computer and use it in GitHub Desktop.
MutationObserver simple
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
// target element that we will observe | |
const target = document.body; | |
// config object | |
const config = { | |
attributes: true, | |
attributeOldValue: true, | |
characterData: true, | |
characterDataOldValue: true, | |
childList: true, | |
subtree: true | |
}; | |
// subscriber function | |
function subscriber(mutations) { | |
mutations.forEach((mutation) => { | |
// handle mutations here | |
console.log(mutation); | |
}); | |
} | |
// instantiating observer | |
const observer = new MutationObserver(subscriber); | |
// observing target | |
observer.observe(target, config); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment