I'm trying to have menuSelected.textContent
(which is my only h4
) changed to the textContent
of what of the option that I choose from the menu. I'm getting this error and I'm wondering what I'm doing wrong. Can y'all please help me? Thank you.
I've tried setting menuSelected.textContent = menu[0].textContent
before the loop, but then it doesn't change when I click on the others menus (menu[1], menu[2], etc.)
var menu = document.querySelectorAll(".menu a");
var menuSelected = document.querySelector("h4");
//menu controls
for(var i = 0; i < menu.length; i++){
menu[i].addEventListener("click", function(){
menuSelected.textContent = menu[i].textContent;
});
}
The console shows this error:
0: Unable to get property 'textContent' of undefined or null reference