Possible duplicate:
Change element CSS class using JavaScript
I am trying to set div attributes using this script. And I have a problem in the third line, where I try to get divs from the parent div whose id is "loading". but here is the problem, it looks like there is nothing in the divs variables. Why is that?
Script:
function blink() { document.getElementById("loading").setAttribute("class","loader"); var divs = document.getElementById("loading").getElementsByTagName("div"); alert(divs[0].class); for(var i=0;i<divs.length;i++) { var _id = divs[i].id; document.getElementById(divs[i].id).setAttribute("class", "bar"); } }
HTML:
<div id="loading" class="loader2"> <a href="#" onClick="blink()"> <div class="bar_"></div> <div class="bar_"></div> <div class="bar_"></div></a> </div>
I want to replace the divs: "bar_" class with "bar". what am i trying to do.
source share