title: getElementsByClassName adding style
body: <p>With this code I am looping through the <code>li</code> elements to add the class 'cool'. Just testing different methods such as <code>getElementById</code> and <code>querySelectorAll</code> and they work fine, but when I use <code>getElementsByClassName</code>, it skips every other one out, not applying the style to it. I removed the <code>i++</code> counter which applies it to every element, but wouldn't that lead to an infinite loop? Can anyone explain? </p>
  
  <pre><code>var listItems = document..getElementsByClassName('test');
  
  var i;
  for (i = 0; i &lt; listItems.length; i++) { //loop through elements //remove ++ when using .getElementsByClassName method to select each element
  listItems[i].className = 'cool';// change class to cool
  }
  </code></pre>