title: classList.remove is removing elements from a HTMLCollection?
body: <p>I'm encountering some very strange behaviour with JavaScripts new classList API, say we have the following HTML code:</p>
  
  <pre><code>&lt;p class="testing"&gt;Lorem Ipsum&lt;/p&gt;
  &lt;p class="testing"&gt;Lorem Ipsum&lt;/p&gt;
  </code></pre>
  
  <p>And the following JavaScript code:</p>
  
  <pre><code>var elements = document.getElementsByClassName("testing");
  alert(elements.length);
  elements[0].classList.remove("testing");
  alert(elements.length);
  </code></pre>
  
  <p>The first alert will give you a value of 2, whilst the second alert returns 1.</p>
  
  <p>It appears that removing the class from the element is also removing it from the <code>elements</code> HTMLCollection, which makes absolutely no sense to me.</p>
  
  <p>You can see an example of this code <a href="http://jsfiddle.net/rE79n/1/" rel="noreferrer">HERE</a>.</p>
  
  <p>I encountered this problem when trying to remove a certain class from some elements using code like below:</p>
  
  <pre><code>var elements = document.getElementsByClassName('testing');
  var elementsLength = elements.length - 1;
  for(var i = 0; i &lt;= elementsLength ; i++)
  {
      elements[i].classList.remove('testing');
  }
  </code></pre>
  
  <p>Say we have two elements like in the example above, the loop runs successfully the first time, but the second time it's looking for an element in the HTMLCollection that no longer exists, so I get something like "TypeError: elements[i] is undefined".</p>
  
  <p>You can see an example of the above code <a href="http://jsfiddle.net/2MU57/" rel="noreferrer">HERE</a></p>
  
  <p>This is frustrating to say the least, I can't understand why/how classList.remove could effect what is effectively an array set only once before the classList.remove function is called. I can't even seem to find anything about this behaviour online.</p>
  
  <p>Am I doing something crazy? Or has I unearthed some strange hidden feature of the classList api that no one knows about?</p>