Created
April 6, 2021 21:38
-
-
Save stordahl/32cf68a021906a410b846b6af392a9ca to your computer and use it in GitHub Desktop.
Removing DOM element from parent that loads onClick
This file contains hidden or 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
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