Skip to content

Instantly share code, notes, and snippets.

@vldvel
Last active March 28, 2018 06:58
Show Gist options
  • Save vldvel/03455bd864bde98ea6cb7566cffd9a90 to your computer and use it in GitHub Desktop.
Save vldvel/03455bd864bde98ea6cb7566cffd9a90 to your computer and use it in GitHub Desktop.
MutationObserver Too Long Example
// target element that we will observe
const target = document.querySelector('div');
// config object
const config = {
characterData: true,
characterDataOldValue: true,
childList: true,
subtree: true
};
// subscriber function
function subscriber(mutations) {
mutations.forEach((mutation) => {
if (mutation.addedNodes.length && mutation.addedNodes[0].length > 5) {
mutation.target.innerText = 'too long';
}
});
}
// 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