Skip to content

Instantly share code, notes, and snippets.

@markhallen
Created November 8, 2019 08:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save markhallen/f8119bb4b9c224e9581d1fab7408036c to your computer and use it in GitHub Desktop.
Save markhallen/f8119bb4b9c224e9581d1fab7408036c to your computer and use it in GitHub Desktop.
// crude first implementation for proof
document.addEventListener('DOMContentLoaded', () => {
// Select the node that will be observed for mutations
const targetNode = document.getElementById('modal-holder');
// Options for the observer (which mutations to observe)
const config = { attributes: true, childList: true, subtree: true };
// Callback function to execute when mutations are observed
const callback = function(mutationsList, observer) {
for(let mutation of mutationsList) {
if (mutation.type === 'childList') {
console.log('A child node has been added or removed.');
}
else if (mutation.type === 'attributes') {
console.log('The ' + mutation.attributeName + ' attribute was modified.');
}
}
};
// Create an observer instance linked to the callback function
const observer = new MutationObserver(callback);
// Start observing the target node for configured mutations
observer.observe(targetNode, config);
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment