HTML and CSS Reference
EXPLANATION ( CONTINUED )
Rather than starting at the top of the DOM tree to obtain the text between the
HTML tags, it is easier to get a reference to the tag and then add the DOM prop-
erties to the reference as shown here. An even easier way to fetch the text value
between the tags is to use the innerHTML property described later in this chapter.
Figure 15.9 HTML elements are objects.
To reference a collection of elements in a document, such all the <p> tags, <h1> tags, or
<a> tags in your document, you can use the getElementsByTagName() method. This
method takes the name of the element as its argument and returns a list of all the nodes
of that name in the document. If you need to collectively change the values of a partic-
ular element, such as all the links in an <a> tag, do this by manipulating the reference
returned by the getElementsByTagName(). Use the DOM nodes to continue walking
down the tree from the point of reference retrieved from document.getElementsByTag-
Name() method as shown in Example 15.3.