I’m trying to select every third element of a parent with javascript and add a css class to it. Sounds pretty simple to me but I can’t get it work.
I found this thread which looked quite nice to me to get that done, but I’m such a wuss with javascript that my tries didn’t work out:
var nodes = document.getElementsByClassName("ParentsClassName").childNodes;
for(i=0; i<nodes.length; i+=3) {
this.className += ' newClassName';
}
When I load this, nothing happens at all.
Any fixes, eyeopeners and tips appreciated.
Greetings, Marian
Or with loops