Skip to content

Instantly share code, notes, and snippets.

@stordahl
Created April 6, 2021 21:38
Show Gist options
  • Save stordahl/32cf68a021906a410b846b6af392a9ca to your computer and use it in GitHub Desktop.
Save stordahl/32cf68a021906a410b846b6af392a9ca to your computer and use it in GitHub Desktop.
Removing DOM element from parent that loads onClick
window.addEventListener("DOMContentLoaded", function() {
const targetNode = document.getElementById('rpressModal')
const config = { attributes: true, childList: true, subtree: true };
const removeFirst = (e) => {
e.selectedIndex = "2";
}
const callback = function(mutationsList, observer) {
for(const mutation of mutationsList) {
if (mutation.type === 'childList') {
console.log('A child node has been added or removed.');
let firstLoop = true
if(firstLoop){
const select = document.getElementById('rpress-pickup-hours')
removeFirst(select)
} else { return }
}
}
};
const observer = new MutationObserver(callback);
observer.observe(targetNode, config);
}, false);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment