sylhare / Type-on-Strap

🎨 Simplistic, responsive jekyll based open source theme
https://sylhare.github.io/Type-on-Strap/
MIT License
814 stars 902 forks source link

ensure element exists before access it #356

Closed yshrsmz closed 2 years ago

yshrsmz commented 2 years ago

I got the following error when I created a layout without a header.

Uncaught TypeError: Cannot read properties of null (reading 'addEventListener')
    at main.min.js:1:2293
    at Array.forEach (<anonymous>)
    at HTMLDocument.<anonymous> (main.min.js:1:2271)
Uncaught TypeError: Cannot set properties of null (setting 'innerHTML')
    at setMode (main.min.js:1:1492)
    at window.onload (main.min.js:1:1803)

so added null checks to ensure that we use these elements when it actually exists.

yshrsmz commented 2 years ago

thanks!