Node in an HTML document tree.
Attributes for an element node.
|
Show Details |
4.0+ |
1.0+ |
6.0+ |
7.0+ |
1.0+ |
-
For examples, see the quirksmode test page:
http://www.quirksmode.org/dom/tests/attributes.html
- Remarks
-
This property returns a listing of all the attributes bound to this Node . Since only
Element nodes support attributes, most Node types will return a null
value for this property.
NamedNodeMap s are essentially the DOM-equivilant of a hash. This property provides an alternative
to the specific Element.getAttribute and Element.hasAttribute methods, which are
usually used when you already know which attributes an element has. For those circumstances when you want to do
some automatic discovery of attributes and their values, this property provides a convenient way to iterate through
the element's attributes.
This property also has the added benefit of being usable across all nodes, not just Element nodes.
Therefore no checking needs to be done ahead of time to verify if a node is an Element ; rather you
can iterate over the attributes list, since any element that has no attributes, or any other DOM node,
will have a null value for this property.
- Availability
-
HTML DOM Level 1|HTML DOM Level 2|W3C
|
Child nodes of the current node.
|
Show Details |
4.0+ |
1.0+ |
6.0+ |
7.0+ |
1.0+ |
-
For examples, see the quirksmode test page:
http://www.quirksmode.org/dom/tests/children.html
- Remarks
-
The list of nodes that are immediate children of this node. The DOM is a heirarchial structure of Node
objects. This property, combined with the parentNode properties provide the basics for defining
this structure. Several convenience properties are provided for accessing some frequently-used children nodes, namely the
firstChild and lastChild properties.
Since the NodeList class can be referenced as an array as well as its object-oriented interface,
one can easily iterate through the contents of a node using standard JavaScript for loops. Because
this property is read-only, you cannot alter the NodeList to effect this node's contents. Instead,
the methods for addeding and removing nodes should be used, which will result in this being updated automatically.
- Availability
-
HTML DOM Level 1|HTML DOM Level 2|W3C
|
First child node of the current node.
|
Show Details |
4.0+ |
1.0+ |
6.0+ |
7.0+ |
1.0+ |
-
For examples, see the quirksmode test page:
http://www.quirksmode.org/dom/tests/nodetree.html
- Remarks
-
Returns the first child node from the list of the current node's children. If this node doesn't have any
children, a null value will be returned.
This is functionally equivilant to invoking node.childNodes.NodeList.item(0) ,
though this
method is much more suscinct and doesn't require any error trapping if the child node doesn't exist.
- Availability
-
HTML DOM Level 1|HTML DOM Level 2|W3C
|
Last child node of the current node.
|
Show Details |
4.0+ |
1.0+ |
6.0+ |
7.0+ |
1.0+ |
-
For examples, see the quirksmode test page:
http://www.quirksmode.org/dom/tests/nodetree.html
- Remarks
-
Returns the last child node from the list of the current node's children. If this node doesn't have any
children, a null value will be returned.
This is functionally equivilant to invoking node.childNodes.NodeList.item(node.childNodes.NodeList.length
- 1) , though this
method is much more suscinct and doesn't require any error trapping if the child node doesn't exist.
- Availability
-
HTML DOM Level 1|HTML DOM Level 2|W3C
|
Local part of an element or attribute name if it the node was defined with an XML Namespace.
|
Show Details |
4.0+ |
1.0+ |
6.0+ |
7.0+ |
1.0+ |
- Availability
-
HTML DOM Level 2|W3C
|
URI of the namespace for an element or attribute node if the node was defined with an XML Namespace.
|
Show Details |
4.0+ |
1.0+ |
6.0+ |
7.0+ |
1.0+ |
- Availability
-
HTML DOM Level 2|W3C
|
Sibling node immediately after the current node.
|
Show Details |
4.0+ |
1.0+ |
6.0+ |
7.0+ |
1.0+ |
-
For examples, see the quirksmode test page:
http://www.quirksmode.org/dom/tests/nodetree.html
- Remarks
-
Returns the next node to the current one within the parent node's children. If this node is the last child
within it's parent, then a null value will be returned.
When working with a node, it is often useful to be able to manipulate or search the nodes surrounding it. For instance, if
given
a node representing a label, you might want to find the text node immediately next to it. To help with this, the
nextSibling property allows you to traverse to neighboring nodes in the DOM.
- Availability
-
HTML DOM Level 1|HTML DOM Level 2|W3C
|
Name of the node. Same as tag name for element nodes.
|
Show Details |
4.0+ |
1.0+ |
6.0+ |
7.0+ |
1.0+ |
-
For examples, see the quirksmode test page:
http://www.quirksmode.org/dom/tests/aboutnodes.html
- Remarks
-
This returns a name that represents this node's name. Depending on the type of object this is, this property will either
return the name identifying this object; for instance, if this node is a Element or Attr object,
then the tag or attribute name is returned. In other cases some place-holder text will be returned.
nodeName node-type valuesTypeleftValueleftAttr
Attribute name
|
CDATASection #cdata-section |
Comment #comment |
Document #document |
DocumentFragment #document-fragment |
DocumentType
Document type name
|
Element
Tag name
|
Entity
Entity name
|
EntityReference
Name of entity referenced
|
Notation
Notation name
|
ProcessingInstruction
Target
|
Text #text |
If XML Namespaces were defined for this node and this node is a Element or
Attr object (since these are the only node types that support the use of namespaces),
this property returns the node name including the prefix and localName.
Returns an upper case tag name.
- Availability
-
HTML DOM Level 1|HTML DOM Level 2|W3C
|
Type of node. See Remarks for valid values.
|
Show Details |
5.5+ |
1.0+ |
6.0+ |
7.0+ |
1.0+ |
- IE: IE 5.0 on Windows does not assign nodeType attributes. Fixed in IE 5.5.
-
For examples, see the quirksmode test page:
http://www.quirksmode.org/dom/tests/aboutnodes.html
- Remarks
-
This property returns an integer indicating what type of DOM Node this object represents.
Because the Node class is inherited by several other, more specific DOM objects, this property
is a programmatic way of determining what an arbitrary node is, and therefore can tell the programmer how to interact
with it. There are a series of constants defined in this object that can be used to refer to this property:
nodeList constant valuesValuerightConstantleft1 ELEMENT_NODE|
2 ATTRIBUTE_NODE|
3 TEXT_NODE|
4 CDATA_SECTION_NODE|
5 ENTITY_REFERENCE_NODE|
6 ENTITY_NODE|
7 PROCESSING_INSTRUCTION_NODE|
8 COMMENT_NODE|
9 DOCUMENT_NODE|
10 DOCUMENT_TYPE_NODE|
11 DOCUMENT_FRAGMENT_NODE|
12 NOTATION_NODE|
- Availability
-
HTML DOM Level 1|HTML DOM Level 2|W3C
|
Value of the current node.
|
Show Details |
4.0+ |
1.0+ |
6.0+ |
7.0+ |
1.0+ |
-
For examples, see the quirksmode test page:
http://www.quirksmode.org/dom/tests/aboutnodes.html
- Remarks
-
This represents the value of the node. Only Attr , CDATASection , Comment ,
ProcessingInstruction , and Text objects can contain a value in this property. For all
other types of objects this property will return null, and setting it to a different value has no effect.
- Availability
-
HTML DOM Level 1|HTML DOM Level 2|W3C
|
Document object that contains this node.
|
Show Details |
6.0+ |
1.0+ |
6.0+ |
7.0+ |
1.0+ |
-
For examples, see the quirksmode test page:
http://www.quirksmode.org/dom/tests/document.html
- Remarks
-
Refers to the Document object that this node exists in. Because a node must be created as a child of a
Document , and since Node objects cannot be moved arbitrarily from one document to another
(not without duplicating it), this is a way of referring to the parent document for a node so that document-wide method calls
can be used for a node.
- Availability
-
HTML DOM Level 1|HTML DOM Level 2|W3C
|
Parent node of the current node.
|
Show Details |
4.0+ |
1.0+ |
6.0+ |
7.0+ |
1.0+ |
-
For examples, see the quirksmode test page:
http://www.quirksmode.org/dom/tests/nodetree.html
- Remarks
-
This property contains a reference to the parent node for the current node. Since the DOM is a heirarchial structure of
nodes, the parentNode and childNodes properties tie the collection of nodes
together.
Not all nodes can have parents however. Attr , Document , DocumentFragment ,
Entity and Notation objects and as such will contain a null value for this property.
As well this property will be null for newly-created nodes that have yet to be added to a location within the DOM tree.
- Availability
-
HTML DOM Level 1|HTML DOM Level 2|W3C
|
Namespace prefix for an element or attribute node if the node was defined with an XML Namespace.
|
Show Details |
4.0+ |
1.0+ |
6.0+ |
7.0+ |
1.0+ |
- Availability
-
HTML DOM Level 2|W3C
|
Sibling node immediately before the current node.
|
Show Details |
4.0+ |
1.0+ |
6.0+ |
7.0+ |
1.0+ |
-
For examples, see the quirksmode test page:
http://www.quirksmode.org/dom/tests/nodetree.html
- Remarks
-
Returns the previous node to the current one within the parent node's children. If this node is the first child
within it's parent, then a null value will be returned.
- Availability
-
HTML DOM Level 1|HTML DOM Level 2|W3C
|
Appends a node to the childNodes array for the node.
|
Show Details |
5.0+ |
1.0+ |
6.0+ |
7.0+ |
1.0+ |
- IE: Appending an "option" element to a "select" element may crash IE 5.0 on Windows.
Parameters
Node |
newChild |
Node to add to the current element as a child. |
Returns
-
Using appendChildvar newElement = document.Document.createElement('label');
newElement.Element.setAttribute('value', 'Username:');
var usernameText = document.Document.getElementById('username');
usernameText.appendChild(newElement);
For more examples, see the quirksmode test page:
http://www.quirksmode.org/dom/tests/movingnodes.html
- Remarks
-
Add the provided node at the end of this node's children. The newly added node
is returned when the operation is completed. There are a few interesting caveats with this method.
If the node supplied to this method already exists somewhere in the DOM tree, then it is
first removed before being appended. As well, if the value supplied to this method is a DocumentFragment ,
then the entire contents of the fragment are moved to the end of this node's children.
- Throws
-
- Raises a HIERARCHY_REQUEST_ERR error if either the supplied node
is one of this node's ancestors, or if the current node doesn't allow the given type of node as
a child.
- Raises a WRONG_DOCUMENT_ERR error if the supplied node doesn't
exist within this node's document.
- Raises a NO_MODIFICATION_ALLOWED_ERR error if the node is read-only.
- See Also
-
Node.insertBefore|Node.removeChild|Node.replaceChild
- Availability
-
HTML DOM Level 1|HTML DOM Level 2|W3C
|
Creates a copy of either the node or the node and its children.
|
Show Details |
5.0+ |
1.0+ |
6.0+ |
7.0+ |
1.0+ |
- IE: On a Mac, IE 5.0 does not clone the event handlers for an element.
Parameters
Boolean |
deep |
If true, clone the child nodes, also. |
Returns
-
Using cloneNodevar myObject = document.Document.getElementById('EmailAddress');
var newObject = myObject.cloneNode(true);
newObject.id = 'ClonedEmailAddress';
myObject.parentNode.insertBefore(newObject, myObject);
For more examples, see the quirksmode test page:
http://www.quirksmode.org/dom/tests/movingnodes.html
- Remarks
-
Because a Node can only exist in one location in the DOM tree at a time, it is necessary
to create and insert a new node even if you want a simple copy of an element or attribute, or any other kind
of DOM Node . This method, therefore, provides a facility for making an exact duplicate
of a node, capable of being inserted into the DOM tree at another point.
Since Node s are heirarchial, the argument to this method indicates whether or not
you would like this node's children cloned as well. If you pass false into this method,
then only the properties on the node you are cloning will be duplicated.
Once cloned, the new node will have no parent, requiring you to add it somewhere to the DOM tree yourself.
When cloning a Element node, any properties defined by the XML processor, including attributes
and their defaults, will be cloned. It's important to note, however, that the text contents of an
Element are in fact Text nodes, and will not be cloned unless a deep clone is
requested.
If you clone an Attr object explicitly, rather than simply cloning an Element ,
the Attr.specified property is set to true, regardless of whether or not the attribute you are
cloning from was specified.
The requirements of having unique node IDs within a DOM tree still holds true, and as such any unique identifiers
within the cloned nodes need to be changed before you insert them back into the DOM tree.
- Availability
-
HTML DOM Level 1|HTML DOM Level 2|W3C
|
Returns true if the node is an element node with attributes.
|
Show Details |
no |
1.0+ |
6.0+ |
7.0+ |
1.3+ |
Returns
-
Using hasAttributesvar obj = document.Document.getElementById('EmailAddress');
if (obj.hasAttributes()) {
window.alert("The node " + obj.Node.nodeName + " has attributes");
}
For more examples, see the quirksmode test page:
http://www.quirksmode.org/dom/tests/attributes3.html
- Remarks
- Returns true if this node is an
Element and has any attributes. Returns false if there are none. Equivilant to
checking node.attributes .NamedNodeMap.length > 0 .
- See Also
-
Element.getAttribute|Element.hasAttribute|Node.attributes
- Availability
-
HTML DOM Level 1|HTML DOM Level 2|W3C
|
Returns true if the node has child nodes.
|
Show Details |
4.0+ |
1.0+ |
6.0+ |
7.0+ |
1.0+ |
Returns
-
Using hasChildNodesvar obj = document.Document.getElementById('EmailAddress');
if (obj.hasChildNodes()) {
window.alert("The node " + obj.Node.nodeName + " has children");
}
- Remarks
- Returns true if this node has any child nodes. Returns false if there are none. Equivilant to checking
node.childNodes .NodeList.length
> 0 .
- See Also
-
Node.childNodes
- Availability
-
HTML DOM Level 1|HTML DOM Level 2|W3C
|
Inserts a node into the childNodes array for the node before the specified child node.
|
Show Details |
4.0+ |
1.0+ |
6.0+ |
7.0+ |
1.0+ |
Parameters
Node |
newChild |
Child node to insert. |
Node |
refChild |
Sibling node for the new child. |
Returns
-
Using insertBeforevar obj = document.Document.getElementById('EmailAddress');
var newElement = document.Document.createElement('label');
var refElement = obj.Node.childNodes[3];
try {
obj.insertBefore(newElement, refElement);
} catch DOMException {
// Error handling
};
For more examples, see the quirksmode test page:
http://www.quirksmode.org/dom/tests/movingnodes.html
- Remarks
-
This method is used to insert a new child element at a very specific location in amongst
multiple children. By specifying as the refChild parameter one of the element's children
nodes, the new node will be inserted immediately prior to it.
If the node supplied to this method already exists somewhere in the DOM tree, then it is
first removed before being inserted. As well, if the value supplied to this method is a
DocumentFragment , then the entire contents of the fragment are inserted,
in the same order, before the refChild reference node..
- Throws
-
- Raises a HIERARCHY_REQUEST_ERR error if either the supplied node
is one of this node's ancestors, or if the current node doesn't allow the given type of node as
a child.
- Raises a WRONG_DOCUMENT_ERR error if the supplied node doesn't
exist within this node's document.
- Raises a NO_MODIFICATION_ALLOWED_ERR error if the node is read-only.
- Raises a NOT_FOUND_ERR error if the supplied
refChild
node is not a child of this one.
- See Also
-
Node.appendChild|Node.removeChild|Node.replaceChild
- Availability
-
HTML DOM Level 1|HTML DOM Level 2|W3C
|
isSupported( String feature, [ String version]) : Boolean
Returns true if the specified feature and version are supported.
|
Show Details |
no |
1.0+ |
6.0+ |
7.0+ |
1.0+ |
Parameters
String |
feature |
Name of the feature. |
String |
version |
(optional)Version of the feature.
|
Returns
- Remarks
- Tests whether a node supports the specified feature. Similar to the
DOMImplementation.hasFeature method and
takes the same feature names. If version is null, returns true if any version of the feature is supported.
- See Also
-
DOMImplementation.hasFeature
- Availability
-
HTML DOM Level 2|W3C
|
Merges text nodes adjacent to the element to create a normalized DOM.
|
Show Details |
N/A |
1.0+ |
6.0+ |
7.0+ |
1.0+ |
Returns
-
For examples, see the quirksmode test page:
http://www.quirksmode.org/dom/tests/splittext.html
- Remarks
-
Normalizes any
Text nodes contained under this node and all of its children.
Merges any adjacent Text nodes into one object, so that the nodes reflect how they would be structured if this
XML document were freshly loaded.
Normalize() is useful for manipulating the text content of nodes for editing. Instead
of worrying about altering existing Text nodes, you can simply add new nodes and perform the normalize
when you finish your updates.
- Availability
-
HTML DOM Level 1|HTML DOM Level 2|W3C
|
Removes the specified child node from the element and returns the node.
|
Show Details |
5.0+ |
1.0+ |
6.0+ |
7.0+ |
1.0+ |
Parameters
Node |
oldChild |
Child node to remove. |
Returns
-
Using removeChildvar obj = document.Document.getElementById('EmailAddress');
try {
var oldChild = obj.removeChild(obj.Node.firstChild);
} catch DOMException {
// Error handling
};
For more examples, see the quirksmode test page:
http://www.quirksmode.org/dom/tests/movingnodes.html
- Remarks
- Removes and returns the specified child node from the list of this node's children.
- Throws
-
- Raises a NO_MODIFICATION_ALLOWED_ERR if the node is read-only.
- Raises a NOT_FOUND_ERR if the supplied node is not a child of this one.
- See Also
-
Node.appendChild|Node.insertBefore|Node.replaceChild
- Availability
-
HTML DOM Level 1|HTML DOM Level 2|W3C
|
Removes the specified child node, replaces it with another node, and returns the removed node.
|
Show Details |
5.0+ |
1.0+ |
6.0+ |
7.0+ |
1.0+ |
Parameters
Node |
newChild |
Node to replace the oldChild node with. |
Node |
oldChild |
Node to be replaced. |
Returns
-
Using replaceChildvar obj = document.Document.getElementById('EmailAddress');
var newElement = document.Document.createElement('label');
try {
var oldChild = obj.replaceChild(newElement, obj.Node.lastChild);
} catch DOMException {
// Error handling
};
For more examples, see the quirksmode test page:
http://www.quirksmode.org/dom/tests/movingnodes.html
- Remarks
-
This method simplifies the process of calling
removeChild and then insertBefore , so that you do
not have to worry if this node is the first or last child.
The new child node is removed if it already exists somewhere else in the DOM tree. If the new child is a DocumentFragment
node, the oldChild node is replaced by all of the nodes within the DocumentFragment , in the same
order.
- Throws
-
- Raises a HIERARCHY_REQUEST_ERR error if either the node being inserted is one of this node's ancestors, or if the current
node does not allow this type of node as a child.
- Raises a WRONG_DOCUMENT_ERR error if the newChild node was not created within the current document.
- Raises a NO_MODIFICATION_ALLOWED_ERR if this node is read-only or if the parent of the new node is read-only.
- Raises a NOT_FOUND_ERR if the supplied oldChild node is not a child of this one.
- See Also
-
Node.appendChild|Node.insertBefore|Node.removeChild
- Availability
-
HTML DOM Level 1|HTML DOM Level 2|W3C
|
This object represents a unique node within a DOM tree. It is the lowest-level unit for representing the contents
of an XML document, from which more specific types are derived. Perhaps the most commonly used derivitives of
Node
are Element
, Attribute
and Text
.
You will never actually create a node directly as it is intended to be a basic interface for more specific classes,
but nevertheless the properties and methods defined here are available in many different DOM objects.