Skip to content

Instantly share code, notes, and snippets.

@vldvel
Last active March 22, 2018 10:20
Show Gist options
  • Save vldvel/5a17d906da5cee665f1f576fd25710ba to your computer and use it in GitHub Desktop.
Save vldvel/5a17d906da5cee665f1f576fd25710ba to your computer and use it in GitHub Desktop.
MutationObserver simple
// 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