I am creating a hamburger button which is changing color on the scroll, everything is working fine but the only problem is that I am having an error in the console saying Uncaught TypeError: span[element].style is undefined
Please assist
Here is my JS code
window.addEventListener("scroll", function(){
const headerMenu=document.querySelector(".header__menu");
headerMenu.classList.toggle("changed", window.scrollY > 10);
const li= document.querySelector(".header__menu__ul");
const menuMobile=document.getElementsByClassName("menuMobile")[0];
const span=menuMobile.children;
if (this.window.scrollY>10){
li.style.color="#746B6B";
}
else{
li.style.color="white";
}
for(var element in span){
if (this.window.scrollY>10){
span[element].style.backgroundColor="black";
}
else{
span[element].style.backgroundColor="white";
}
}
});
<div id="menu" class="header__menu">
<img alt="Logo" src="/images/logo.png">
<ul class="header__menu__ul ">
<li class="header__menu__ul__li ">Programs</li>
<li class="header__menu__ul__li">Service</li>
<li class="header__menu__ul__li">News</li>
<li class="header__menu__ul__li"> About Us</li>
<li class="header__menu__ul__li header__menu__ul__li--btn btn-primary"> Let's talk</li>
</ul>
<div class="menuMobile">
<span class="menuMobile__first"></span>
<span class="menuMobile__second"></span>
<span class="menuMobile__third"></span>
</div>
</div>```