Skip to content Skip to sidebar Skip to footer

Changing Classname Issue (javascript And Ie)

The following javascript code does not work correctly. (I am using IE9 and cannot use a different browser or JQuery): var elems = document.getElementsByClassName('EditableTextBox')

Solution 1:

The getElementsByClassName seems to return a live set, so when you change the class of any item the set gets updated immediately, and it will skip each other item. Do the loop in reverse instead:

for (var i = elems.length - 1; i >= 0; --i) {                
    elems[i].className = "Zero";
}

Solution 2:

An alternative would be:

while(list.length!=0) {
    list[0].className = 'Zero';
}

That way you know you can't miss an element.

Post a Comment for "Changing Classname Issue (javascript And Ie)"