Java Reference
In-Depth Information
There are other types not covered in the table, but these aren't used in HTML documents.
As we can see from the table, a code of 1 confirms that body is an element node.
We can also use the nodeName property to find the name of the element:
<< "BODY"
Note that the element name is returned in upper-case letters.
Legacy DOM Shortcut Methods
There are some methods from DOM Level 0 that can still be employed to access commonly
used elements:
document.body returns the body element of a web page, as we saw in the pre-
vious example.
document.images returns a node list of all the images contained in the docu-
document.links returns a node list of all the <a> elements and <area> ele-
ments that have an href attribute.
document.anchors returns a node list of all the <a> elements that have a
name attribute.
document.forms returns a node list of all the forms in the document. This will
be used when we cover forms in Chapter 8 .
Warning: Array- like , but not an Array
Node lists are array-like objects, but they are not arrays. You can access
each item using index notation. For example, document.images[0]
will return the first image in the node list of all the images in the document.
They also have a length property, which can be used to iterate through
every element using a for loop, like so:
Search WWH ::

Custom Search