clear all ASP label fields
<p>I am trying to clear all the fields in my .aspx page using javascript (<em>Should be cross-browser</em>). The below code is working fine for <code>TextBox</code> fields but not for <code>Label</code> fields.</p>

<pre><code>var elements = document.getElementsByTagName("input");
for (var i = 0; i &lt; elements.length; i++) {
    if (elements[i].type == "text") {
        elements[i].value = "";
    }
    else if (elements[i].type == "label") {
        elements[i].value = "";
    }
}
</code></pre>

<p>Later I saw that HTML is rendering asp.net Labels as <code>span</code> so I also tried:</p>

<pre><code>else if (elements[i].type == "span") {
    elements[i].innerHTML = "";
}
</code></pre>

<p>Still the Labels are not being cleared. Am I doing something wrong here?</p>

<p>And the other problem is, whenever I refresh the page, the cleared <code>TextBox</code> fields are again being populated with the old values.. (really frustrating)</p>

<p>I am trying the above code by referring <strong><a href="http://stackoverflow.com/q/569357/1577396">this</a></strong></p>

<p>Please help.</p>
