Main Page

Node.DOCUMENT_NODE

The
<employees/>
node is considered the ancestor of all nodes in this section of the tree, including its
children (the comment and
<employee/>
) as well as their children (
<name/>
,
<position/>
, and so on,
all the way down to the text node
“His birthday is on 8/14/68”
). The document node is consid-
ered the ancestor of all nodes in the document.
The
Node
interface defines 12 constants that map to the different node types (and are used by the
nodeType
property discussed later):
?
Node.ELEMENT_NODE
(1)
?
Node.ATTRIBUTE_NODE
(2)
?
Node.TEXT_NODE
(3)
?
Node.CDATA_SECTION_NODE
(4)
?
Node.ENTITY_REFERENCE_NODE
(5)
?
Node.ENTITY_NODE
(6)
?
Node.PROCESSING_INSTRUCTION_NODE
(7)
?
Node.COMMENT_NODE
(8)
?
Node.DOCUMENT_NODE
(9)
?
Node.DOCUMENT_TYPE_NODE
(10)
?
Node.DOCUMENT_FRAGMENT_NODE
(11)
?
Node.NOTATION_NODE
(12)
The
Node
interface also defines a set of properties and methods that all node types contain. These prop-
erties and methods are listed out in the following table:
Property/Method
Type/Return Type Description
nodeName
String
The name of the node; this is defined depending
on the type of node.
nodeValue
String
The value of the node; this is defined depending
on the type of node.
nodeType
Number
One of the node type constant values
ownerDocument
Document
Pointer to the document that this node belongs to
firstChild
Node
Pointer to the first node in the
childNodes
list
lastChild
Node
Pointer to the last node in the
childNodes
list
childNodes
NodeList
A list of all child nodes
previousSibling
Node
Pointer to the previous sibling;
null
if this is the
first sibling
Table continued on following page
165
DOM Basics
09_579088 ch06.qxd 3/28/05 11:37 AM Page 165


JavaScript EditorFree JavaScript Editor     Ajax Editor


©