setting new class in div

Possible Duplicate:
Change an element’s CSS class with JavaScript

I’m trying to set div’s attributes with this script. And i have problem in third line, where I’m trying to get div-s from parent div which id is "loading". but here the problem, it seems like there in variable divs is nothing. why’s that?


function  blink() {
    var divs = document.getElementById("loading").getElementsByTagName("div");
    for(var i=0;i<divs.length;i++) {
        var _id = divs[i].id;
        document.getElementById(divs[i].id).setAttribute("class", "bar");


<div id="loading" class="loader2">
<a href="#" onClick="blink()">
    <div class="bar_"></div>
    <div class="bar_"></div>
    <div class="bar_"></div></a>

I want to replace divs class: "bar_" to "bar". that’s what I’m trying to do.

72 thoughts on “setting new class in div”

Leave a Comment