Skip to content

Instantly share code, notes, and snippets.

@markhallen
Created November 8, 2019 09:31
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/89ce32c75838d1f198691f6ad7537629 to your computer and use it in GitHub Desktop.
Save markhallen/89ce32c75838d1f198691f6ad7537629 to your computer and use it in GitHub Desktop.
// listen for creation of a modal
$(document).on('click', '.modal-with-react', function() {
addChildListListener('modal-holder')
})
export function addChildListListener(elementId){
// Select the node that will be observed for mutations
const targetNode = document.getElementById(elementId)
// Options for the observer (which mutations to observe)
const config = { childList: true }
// Callback function to execute when mutations are observed
const callback = function(mutationsList, observer) {
for(let mutation of mutationsList) {
if (mutation.type === 'childList') {
insertDatePickers()
// stop observing
observer.disconnect();
}
}
};
// 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