I have few divs with a single class name, my objective is to change the class name value of the div when a particular link is clicked, and below was my approach.
I stored class name values in an array, then used document.getElementsByClassName("test") and stored it into an array elements, and then I ran a for loop to replace class name value. :
function changeClass(value){
style = [ 'view view-first', 'view view-second', 'view view-third', 'view view-fourth', 'view view-fifth' ];
var elements = document.getElementsByClassName("test");
for(var i = elements.length - 1; i >= 0; i++)
{
elements[i].className = style[value];
}
}
When I run this code, only a single div class name is replaced. I want all the class name to be replaced.
i--orfor(var i=0; i<elements.length;i++)