From 7a9b57c56e2fcbee8fd9ebc18330551b747c54a1 Mon Sep 17 00:00:00 2001 From: Neil Brommer Date: Thu, 13 Jul 2023 14:06:38 -0700 Subject: [PATCH] =?UTF-8?q?Prevent=20JS=20errors=20when=20scrolling=20on?= =?UTF-8?q?=20pages=20that=20aren=E2=80=99t=20the=20main=20page?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/js/site.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/js/site.js b/src/js/site.js index 1342192..9e1d18c 100644 --- a/src/js/site.js +++ b/src/js/site.js @@ -33,7 +33,10 @@ document.addEventListener("DOMContentLoaded", () => { const observer = new IntersectionObserver(entries => { entries.forEach(entry => { const id = entry.target.previousElementSibling.id; - const menuListItem = document.querySelector(`nav li a[href="/#${id}"]`).parentElement; + const menuListItem = document.querySelector(`nav li a[href="/#${id}"]`)?.parentElement; + + if (menuListItem == null) + return; if (entry.intersectionRatio > 0) { menuListItem.classList.add("active");