title: setting new class in div
body: <blockquote>
  <p><strong>Possible Duplicate:</strong><br />
  <a href="https://stackoverflow.com/questions/195951/change-an-elements-css-class-with-javascript">Change an element's CSS class with JavaScript</a></p>
  </blockquote>
  
  <p>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 &quot;loading&quot;. but here the problem, it seems like there in variable divs is nothing. why's that?</p>
  <p>Script:</p>
  <pre><code>function  blink() {
      document.getElementById(&quot;loading&quot;).setAttribute(&quot;class&quot;,&quot;loader&quot;);
      var divs = document.getElementById(&quot;loading&quot;).getElementsByTagName(&quot;div&quot;);
      alert(divs[0].class);
      for(var i=0;i&lt;divs.length;i++) {
          var _id = divs[i].id;
          document.getElementById(divs[i].id).setAttribute(&quot;class&quot;, &quot;bar&quot;);
      }       
  }
  </code></pre>
  <p>html:</p>
  <pre><code>&lt;div id=&quot;loading&quot; class=&quot;loader2&quot;&gt;
  &lt;a href=&quot;#&quot; onClick=&quot;blink()&quot;&gt;
      &lt;div class=&quot;bar_&quot;&gt;&lt;/div&gt;
      &lt;div class=&quot;bar_&quot;&gt;&lt;/div&gt;
      &lt;div class=&quot;bar_&quot;&gt;&lt;/div&gt;&lt;/a&gt;
  &lt;/div&gt;
  </code></pre>
  <p>I want to replace divs class: &quot;bar_&quot; to &quot;bar&quot;. that's what I'm trying to do.</p>