diff --git a/assets/ts/scrollspy.ts b/assets/ts/scrollspy.ts index 8a14085..22c0217 100644 --- a/assets/ts/scrollspy.ts +++ b/assets/ts/scrollspy.ts @@ -32,9 +32,11 @@ function buildIdToNavigationElementMap(navigation: NodeListOf): IdToEle const sectionLinkRef: IdToElementMap = {}; navigation.forEach((navigationElement: HTMLElement) => { const link = navigationElement.querySelector("a"); - const href = link.getAttribute("href"); - if (href.startsWith("#")) { - sectionLinkRef[href.slice(1)] = navigationElement; + if (link) { + const href = link.getAttribute("href"); + if (href.startsWith("#")) { + sectionLinkRef[href.slice(1)] = navigationElement; + } } });