Order of the elements returned using getElementsByTagName ()
<p>Reading the controls using getElemetntsByTagName is very common practice to read the element. However i would like to know that whether we can trust the order in which the elements are returned using this function. </p>

<p>Does it return element in the order in which they are placed on the UI ? Or it can return random elements too where we cant trust on the sequence at other times?</p>

<pre><code>var labels = document.getElementsByTagName("label"), i;
for(i=0;i&lt;labels.length;i++)
{
    if(i == 1)
        labels[i].innerText = "First Value";
    else if (i==2)
        labels[i].innerText = "Second Value";

    if (labels[i].innerText  == "NULL") {
        labels[i].innerText  = "Empty";
    }
}
</code></pre>
