![link to this example [link]](../images/permalink.gif)
Example: Loop through every element
var allElements, thisElement; allElements = document.getElementsByTagName('*'); for (var i = 0; i < allElements.length; i++) { thisElement = allElements[i]; // do something with thisElement }
![]() |
You should only do this if you really need to do something with every element. If you know in advance that you only want to operate on certain elements, it will be faster to use an XPath query to get exactly the elements you want. See Doing something for every element with a certain attribute for more information. |