a node in a document tree |
|
Subclasses
Attr, Comment, Document, DocumentFragment, Element, Text
Constants
All nodes in an HTML document are instances of one of the Node
subclasses listed above. Every Node object has a
nodeType property that specifies which of the
subclasses it is an instance of. The following constants are the
legal values for nodeType. Note that these are
static properties of Node, not properties of
individual Node objects. They are not defined in Internet Explorer 4,
5, or 6; in those browsers you must use the corresponding integer
literals.
Node.ELEMENT_NODE = 1; // Element
Node.ATTRIBUTE_NODE = 2; // Attr
Node.TEXT_NODE = 3; // Text
Node.COMMENT_NODE = 8; // Comment
Node.DOCUMENT_NODE = 9; // Document
Node.DOCUMENT_FRAGMENT_NODE=11; // DocumentFragment
Properties
- attributes[ ]
-
If this Node is an Element, the attributes
property is a read-only array of Attr objects that represent the
attributes of the element. The array can be indexed by number or by
attribute name. All HTML attributes have corresponding Element
properties, however, so it is uncommon to use the
attributes[ ] array.
- childNodes[ ]
-
This read-only array of Node objects contains the children of this
node. If the node has no children, this property is a zero-length
array.
- firstChild
-
This read-only property refers to the first child Node of this node,
or null if the node has no children.
- lastChild
-
This read-only property refers to the last child Node of this node,
or null if the node has no children.
- nextSibling
-
The sibling Node that immediately follows this one in the
childNodes[ ] array of the
parentNode, or null if there is
no such node. Read-only.
- nodeName
-
The name of the node. For Element nodes, this property specifies the
tag name of the element, which can also be retrieved with the
tagName property of Element. For Attr nodes, this
property specifies the attribute name. For other types of nodes, the
value is a constant string that specifies the node type. Read-only.
- nodeType
-
The type of the node. The legal values for this property are defined
by the constants listed above.
- nodeValue
-
The string value of a node. For Text and Comment nodes, this property
holds the text content. For Attr nodes, it holds the attribute value.
This property is read/write.
- ownerDocument
-
The Document object of which this Node is a part. For Document nodes,
this property is null. Read-only.
- parentNode
-
The parent or container Node of this node, or null
if there is no parent. Note that Document and Attr nodes never have
parent nodes. Nodes that have been removed from the document or are
newly created and have not yet been inserted into the document tree
have a parentNode of null.
Read-only.
- previousSibling
-
The sibling Node that immediately precedes this one in the
childNodes[ ] array of the
parentNode, or null, if there
is no such node.
Methods
- addEventListener( type, listener, useCapture)
-
Registers an event listener for this node.
type is a string that specifies the event
type minus the "on" prefix (e.g.,
"click" or
"submit").
listener is the event handler function.
When triggered, it is invoked with an Event object as its argument.
If useCapture is true,
this is a capturing event handler. If false or
omitted, it is a regular event handler. Returns nothing. DOM Level 2;
not supported in IE 4, 5, or 6.
- appendChild( newChild)
-
Adds the newChild Node to the document
tree by appending it to the childNodes[ ] array of
this node. If the node is already in the document tree, it is first
removed before being reinserted at its new position. Returns the
newChild argument.
- cloneNode( deep)
-
Returns a copy of this node. If deep is
true, the descendents of the node are recursively
copied as well.
- hasAttributes( )
-
Returns true if this node is an Element and has
any attributes. DOM Level 2.
- hasChildNodes( )
-
Returns true if this node has any children.
- insertBefore( newChild, refChild)
-
Inserts the newChild Node into the
document tree immediately before the
refChild Node, which must be a child of
this node. If the node being inserted is already in the tree, it is
first removed. Returns newChild.
- isSupported( feature, version)
-
Returns true if the specified version number of a
named feature is supported by this node. See also
DOMImplementation.hasFeature( ). DOM Level 2.
- normalize( )
-
Normalizes all Text node descendants of this node by deleting empty
Text nodes and merging adjacent Text nodes. Returns nothing.
- removeChild( oldChild)
-
Removes the oldChild Node from the
document tree. oldChild must be a child of
this node. Returns oldChild.
- removeEventListener( type, listener, useCapture)
-
Removes the specified event listener. Returns nothing. DOM Level 2;
not supported in IE 4, 5, or 6.
- replaceChild( newChild, oldChild)
-
Replaces the oldChild Node (which must be
a child of this node) with the newChild
Node. If newChild is already in the
document tree, it is first removed from its current location. Returns
oldChild.
See Also
Attr, Comment, Document, DocumentFragment, Element, Text
|