Interface Node

The Node interface is the primary datatype for the entire Document Object Model. It represents a single node in the document tree. While all objects implementing the Node interface expose methods for dealing with children, not all objects implementing the Node interface may have children. For example, Text nodes may not have children, and adding children to such nodes results in a DOMException being raised.

The attributes nodeName, nodeValue and attributes are included as a mechanism to get at node information without casting down to the specific derived interface. In cases where there is no obvious mapping of these attributes for a specific nodeType (e.g., nodeValue for an Element or attributes for a Comment), this returns null. Note that the specialized interfaces may contain additional and more convenient mechanisms to get and set the relevant information.

Template arguments

interface Node(DOMString);

Properties

Name Type Description
attributes [get] NamedNodeMap!DOMString A NamedNodeMap containing the attributes of this node (if it is an Element) or null otherwise.
baseURI [get] DOMString The absolute base URI of this node or null if the implementation wasn't able to obtain an absolute URI
childNodes [get] NodeList!DOMString A NodeList that contains all children of this node. If there are no children, this is a NodeList containing no nodes.
firstChild [get] Node!DOMString The first child of this node. If there is no such node, this returns null.
lastChild [get] Node!DOMString The last child of this node. If there is no such node, this returns null.
localName [get] DOMString Returns the local part of the qualified name of this node.
namespaceURI [get] DOMString The namespace URI of this node, or null if it is unspecified. This is not a computed value that is the result of a namespace lookup based on an examination of the namespace declarations in scope. It is merely the namespace URI given at creation time. For nodes of any type other than ELEMENT and ATTRIBUTE and nodes created with a DOM Level 1 method, such as Document.createElement, this is always null.
nextSibling [get] Node!DOMString The node immediately following this node. If there is no such node, this returns null.
nodeName [get] DOMString The name of this node, depending on its type.
nodeType [get] NodeType A code representing the type of the underlying object.
nodeValue [get, set] DOMString The value of this node, depending on its type.
ownerDocument [get] Document!DOMString The Document object associated with this node. This is also the Document object used to create new nodes. When this node is a Document or a DocumentType which is not used with any Document yet, this is null.
parentNode [get] Node!DOMString The parent of this node. All nodes, except Attr, Document, DocumentFragment, Entity, and Notation may have a parent. However, if a node has just been created and not yet added to the tree, or if it has been removed from the tree, this is null.
prefix [get, set] DOMString The namespace prefix of this node, or null if it is unspecified. When it is defined to be null, setting it has no effect, including if the node is read-only. Note that setting this attribute, when permitted, changes the nodeName attribute, which holds the qualified name, as well as the tagName and name attributes of the Element and Attr interfaces, when applicable. Setting the prefix to null makes it unspecified, setting it to an empty string is implementation dependent. Note also that changing the prefix of an attribute that is known to have a default value, does not make a new attribute with the default value and the original prefix appear, since the namespaceURI and localName do not change. For nodes of any type other than ELEMENT and ATTRIBUTE and nodes created with a DOM Level 1 method, such as createElement from the Document interface, this is always null.
previousSibling [get] Node!DOMString The node immediately preceding this node. If there is no such node, this returns null.

Methods

Name Description
cloneNode Returns a duplicate of this node, i.e., serves as a generic copy constructor for nodes. The duplicate node has no parent (parentNode is null) and no user data. User data associated to the imported node is not carried over. However, if any UserData handlers has been specified along with the associated data these handlers will be called with the appropriate parameters before this method returns.
compareDocumentPosition Compares the reference node, i.e. the node on which this method is being called, with a node, i.e. the one passed as a parameter, with regard to their position in the document and according to the document order.
getUserData Retrieves the object associated to a key on a this node. The object must first have been set to this node by calling setUserData with the same key.
hasAttributes Returns whether this node (if it is an element) has any attributes.
hasChildNodes Returns whether this node has any children.
insertBefore Inserts the node newChild before the existing child node refChild. If refChild is null, insert newChild at the end of the list of children. If newChild is a DocumentFragment object, all of its children are inserted, in the same order, before refChild. If the newChild is already in the tree, it is first removed.
isDefaultNamespace This method checks if the specified namespaceURI is the default namespace or not.
isSupported Tests whether the DOM implementation implements a specific feature and that feature is supported by this node.
lookupNamespaceURI Look up the namespace URI associated to the given prefix, starting from this node.
lookupPrefix Look up the prefix associated to the given namespace URI, starting from this node. The default namespace declarations are ignored by this method.
normalize Puts all Text nodes in the full depth of the sub-tree underneath this Node, including attribute nodes, into a "normal" form where only structure (e.g., elements, comments, processing instructions, CDATA sections, and entity references) separates Text nodes, i.e., there are neither adjacent Text nodes nor empty Text nodes. This can be used to ensure that the DOM view of a document is the same as if it were saved and re-loaded.
removeChild Removes the child node indicated by oldChild from the list of children, and returns it.
replaceChild Replaces the child node oldChild with newChild in the list of children, and returns the oldChild node. If newChild is a DocumentFragment object, oldChild is replaced by all of the DocumentFragment children, which are inserted in the same order. If the newChild is already in the tree, it is first removed.
setUserData Associate an object to a key on this node. The object can later be retrieved from this node by calling getUserData with the same key.

Authors

Lodovico Giaretta

Copyright

Copyright Lodovico Giaretta 2016 --

License

Boost License 1.0.