When you remove the nodes from a document, the list of nodes that you just obtained from getElementsByTagName()
gets updated too to avoid lingering references, so you should just keep removing the first node until none remain.
var nodes = document.getElementsByTagName("label");
for (var i = 0, len = nodes.length; i != len; ++i) {
nodes[0].parentNode.removeChild(nodes[0]);
}
Here, the value of nodes.length
is cached; otherwise it would keep decreasing and you end up only removing half :)