- 121 -
Type
:
NodeList node
Description
: This property is a NodeList collection that holds all the children of this node.
A NodeList is still returned, even if the node doesn’t
have any children; the length
property on childNodes will just be set to 0. The reader is
encouraged to take a quick
peek at the NodeList description found in this chapter.
attributes
Type
: NamedNodeMap node
Description
: This property is a NamedNodeMap collection that holds
all the attributes of a
node. The attributes property is set to null for all nodes that aren’t Elements,
Entities, or
Notation, because only these nodes can have attributes. A NamedNodeMap is still
returned, even if the node doesn’t have any attributes. The NamedNodeMap is described
in detail further in this chapter.
parentNode
Type
: Node
Description
: This property is a pointer to the parent of the node. Figures 4.13 through
4.19 show the relationships between the parents and children of nodes.
Note that, in the
figure, a NodeList collection
is often directly above a node, but parentNode points to the
node above the collection. The following example illustrates this behavior.
Example
:
Both alerts in this example return element1, because the parentNode
property allows a
programmer to walk up a tree in addition to moving down. Figure 5.6 gives further insight
by showing what the DOM exposes for the above example.