+ 1

I have created a navbar. But my javascript code not working. I don't what to do... Can anyone please help me.

const hamburger = document.querySelector(".hamburger"); const navLinks = document.querySelector(".nav-links"); const links = document.querySelectorAll(".nav-links li"); hamburger.addEventListener("click", () => { navLinks.classList.toggle("open"); links.forEach(link => { link.classList.toggle("fade"); }); }); https://code.sololearn.com/Wl55UpXP6y42/?ref=app

26th May 2020, 8:16 AM
Sourav Chakraborty
Sourav Chakraborty - avatar
2 Respuestas
+ 2
Sourav Chakraborty Write your JavaScript code inside this function window.onload = function() { }
26th May 2020, 8:43 AM
A͢J
A͢J - avatar
+ 2
window.onload=function(){ js code goes here } it prevents js from getting loaded before html
26th May 2020, 8:43 AM
Abhay
Abhay - avatar