I am writing some vanilla JavaScript to create a nice navigation menu. I am stuck on adding an active class.
I am getting elements by class name NOT by id. The belo
document.getElementsByClassName returns a node list. So you'll have to iterate over the list and bind the event to individual elements. Like this...
var buttons = document.getElementsByClassName("navButton");
for(var i = 0; i < buttons.length; ++i){
buttons[i].onmouseover = function() {
this.setAttribute("class", "active");
this.setAttribute("src", "images/arrows/top_o.png");
}
}