Last active
March 28, 2018 06:58
-
-
Save vldvel/03455bd864bde98ea6cb7566cffd9a90 to your computer and use it in GitHub Desktop.
MutationObserver Too Long Example
This file contains 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.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