HTML and CSS Reference
In-Depth Information
EXPLANATION ( CONTINUED )
9
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.
15.6.2 The document.getElementsByTagName() Method
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.
 
 
Search WWH ::




Custom Search