Created
November 8, 2019 08:38
-
-
Save markhallen/f8119bb4b9c224e9581d1fab7408036c to your computer and use it in GitHub Desktop.
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
// 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