Loop through every element in an HTMLCollection:
<!DOCTYPE html> <html> <body> <p>Loop through each HTML element on this page, and write its tag name:</p> <script> var x, i, l; x = document.getElementsByTagName("*"); l = x.length;/*from w w w . ja v a 2s. c o m*/ for (i = 0; i < l; i++) { document.write(x[i].tagName + "<br>"); } </script> </body> </html>