const targetEl = document.querySelector("#theButtonOrElement"); const watchedEl = document.querySelector("#TheElementYoureWatching"); const intersectionObserver = new IntersectionObserver((entries) => { if (entries[0].intersectionRatio > 0) { footerTopButton.setAttribute("data-visible", false); } else { footerTopButton.setAttribute("data-visible", true); } }); if (targetEl && watchedEl) { targetEl.setAttribute("data-visible", false); intersectionObserver.observe(watchedEl); }