getElementsByTagName
If we are going to remove JavaScript from our code in our local pages, then we need a powerful way to get at things in large chunks. Fortunately, the DOM Core Level 1 provides just such a tool called getElementsByTagName. The W3C explains it like so:
Returns a NodeList of all the Elements with a given tag name in the order in which they would be encountered in a preorder traversal of the Document tree.
Parameters
tagname - The name of the tag to match on. The special value "*
" matches all tags
Return Value
A new NodeList object containing all the matched Elements.
That sounds a bit technical in typical W3C style. The first thing talked about is a NodeList. A NodeList is an ordered collection of nodes – which is similar to an array. Remember that an array looks like this:
vehicleArray
[0] Car
1] Truck
[2] Van
[3] Sled
And you could use various methods to manipulate the data in such an array. An ordered collection is almost the same thing. It’s simply a collection of the nodes that match the element you specified as the parameter. And there are various ways you can then get at that information. This is exactly what we need.