http://jsfiddle.net/9UQwM/1/
the script removes class from the elements in an alternating pattern,
most importantly why?
and what can be done to fix the problem?
Object.prototype.removeClass = function (class_name) {
if (this.length) {
for (i = 0; i < this.length; i++) {
this[i].classList.remove(class_name);
}
}
}
document.getElementsByClassName("test").removeClass("test");
Because when you delete, the next index moves down one. Loop in the opposite direction.
http://jsfiddle.net/9UQwM/2/
Using a while loop might bring more into it
The output would be 7,6,5,4,3,2,1
http://jsfiddle.net/9UQwM/4/
So
thisis updated when you remove the class