0

Javascript NullPointerException. The same below code is running errors free in my Ide but get errors in sololearn ide

const burElement = document.querySelector(".humburger") const navElement = document.querySelector(".nav"); burElement.addEventListener("click",()=>{ navElement.classList.toggle("nav-open"); burElement.classList.toggle("hum-open") }); navElement.addEventListener("click",()=>{ navElement.classList.remove("nav-open"); burElement.classList.remove("hum-open") }); https://sololearn.com/compiler-playground/WaHPSa9E6UiN/?ref=app

1st Oct 2024, 12:30 PM
DevjiCoder
DevjiCoder - avatar
1 Resposta
+ 2
it's because you access dom before it's created The quick fix is to wrap everything in an onload event onload = () => { // All your code }
2nd Oct 2024, 12:44 AM
「HAPPY TO HELP」
「HAPPY TO HELP」 - avatar