JavaScript Error in __main.js Blocking Other Scripts
-
I’m experiencing a JavaScript error on my staging site that’s preventing other scripts from running. The error occurs in your __main.js file at line 70.
Error:
Uncaught TypeError: Cannot read properties of null (reading 'split') at __main.js:70Issue: The click event listener assumes all anchor tags have an
hrefattribute, but when it encounters an anchor without one (or with an empty href), it throws an error at this line:javascript
let navigationToElement = document.getElementById(a.getAttribute('href').split('#')[1]);Impact: This error stops all subsequent JavaScript on the page from executing, including our custom scripts.
Suggested Fix: Add a null/validity check before the
.split()call:javascript
let href = a.getAttribute('href'); if (!href || !href.includes('#')) { return; } let navigationToElement = document.getElementById(href.split('#')[1]);Could you please fix this in the next update or advise on a workaround?
You must be logged in to reply to this topic.