Hello All, I am trying to run a footer script to delete some elements from a Calendar block. For some reason querySelectorAll('item.item--ongoing') seems to be firing before the page fully loads even though I am checking for 'complete' ready state. When I run querySelectorAll in the browser console it picks them up so it's a loading issue.
Is there a way to wait longer for the script to run?
<script >
(function () {
if (window.NodeList && !NodeList.prototype.forEach) {
NodeList.prototype.forEach = Array.prototype.forEach;
}
document.addEventListener('readystatechange', event => {
if (document.readyState === "complete") {
init()
}
});
function init() {
var monthlyEl = document.querySelectorAll('.item.item--ongoing');
console.log('item--ongoing',monthlyEl.length)
new MutationObserver(function() {
init();
// myFunction2(); , etc...
}).observe(document.body, {attributes:true, attributeFilter:["class"]});
})();
</script>