Have a quick question that I think is relatively simple, I'm just missing something. I have a navbar that when the menu items are hovered, I want to append a class of "open" to them". I'm using the following code:
function setNavItemToOpen(navItem){
navItem.classList.add('open');
}
document.addEventListener("DOMContentLoaded", function(){
var primaryNavMenuItems = document.getElementsByClassName('primarynav__menuitem');
for(var i = 0; i < primaryNavMenuItems.length; i++) {
primaryNavMenuItems[i].addEventListener("mouseenter", function(){
setNavItemToOpen(primaryNavMenuItems[i]);
});
};});
The console is telling me that "navItem" is undefined in the function. Is my code for adding the event listener not correct?