I am trying to learn javascript, without using jQuery and others.
I'm having this error: Cannot call method 'getElementsByTagName' of undefined
I know what the problem of the error, but it does not know to solve it. how can I avoid this error in the future?
var menu = document.getElementsByClassName("menu-item");
var i;
for (i = 0; i < menu.length; i = i + 1) {
menu[i].addEventListener("mouseenter", function () {
setInterval(function(){
menu[i].getElementsByTagName("a").css("color","red")
},5000)
})
}