Javascript: getElementsByClassName not giving all elements
<p>Well i put tablerows with a classname "gone" in my Html like this:</p>

<pre><code> &lt;tr class="gone"&gt;
        &lt;th&gt;text&lt;/th&gt;
        &lt;td&gt;text&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr class="gone"&gt;
        &lt;th&gt;text&lt;/th&gt;
        &lt;td&gt;text&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr class="gone"&gt;
        &lt;th&gt;text&lt;/th&gt;
        &lt;td&gt;text&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr class="gone"&gt;
        &lt;th&gt;text&lt;/th&gt;
        &lt;td&gt;text&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr class="gone"&gt;
        &lt;th&gt;text&lt;/th&gt;
        &lt;td&gt;text&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr class="gone"&gt;
        &lt;th&gt;text&lt;/th&gt;
        &lt;td&gt;text&lt;/td&gt;
    &lt;/tr&gt;
</code></pre>

<p>and when i get my elements in javascript with this code: </p>

<pre><code>var arrayelements=document.getElementsByClassName('gone');
var arrlength=arrayelements.length;
for(var i=0;i&lt;arrlength;i++){
    arrayelements[i].setAttribute("class","there");
    console.log(arrayelements);
}
</code></pre>

<p>the return value of my console.log is </p>

<pre><code>&gt; &lt;tr class="there"&gt;...&lt;/tr&gt; 
&gt; &lt;tr class="there"&gt;...&lt;/tr&gt;
&gt; &lt;tr class="there"&gt;...&lt;/tr&gt;
&gt; undefined
</code></pre>

<p>the next time i run it the result is </p>

<pre><code>&gt; &lt;tr class="there"&gt;...&lt;/tr&gt; 
&gt; &lt;tr class="there"&gt;...&lt;/tr&gt;
&gt; undefined
</code></pre>

<p>i don't understand why it is suddenly undefined</p>