Core API
|
Object |
Description |
Availability |
|---|---|---|
|
Represents an attribute of an Element object. |
4.6 or later |
|
|
Represents a block of escaped text, such as XML fragments, source code, or other content that is otherwise interpreted as XML markup. |
4.6 or later |
|
|
Accesses character data in the DOM. |
4.6 or later |
|
|
Represents the contents of a comment within a document. |
4.6 or later |
|
|
Represents the entire HTML or XML document. It acts as the root of the tree, and provides the primary access to the data of the document. |
4.6 or later |
|
|
A lightweight Document object, that creates or extracts only part of a document. |
4.6 or later |
|
|
Represents the doctype for a document. If a document has a doctype, it will be a reference to this object. |
4.6 or later |
|
|
Defines the methods for performing the operations that are independent of any particular instance of the DOM, such as creating new documents. |
4.6 or later |
|
|
Represents an element in an HTML or XML document. |
4.6 or later |
|
|
Represents any entity in an XML document. |
4.6 or later |
|
|
Represents a reference to an Entity object within the document. |
4.6 or later |
|
|
Represents a collection of nodes that can be accessed by name. |
4.6 or later |
|
|
Represents a unique node within the DOM tree, and is the primary data type for the DOM. |
4.6 or later |
|
|
Contains an ordered collection of nodes. |
4.6 or later |
|
|
Represents a notation that is declared in a DTD. |
4.6 or later |
|
|
Represents a processing instruction for an XML document. |
4.6 or later |
|
|
Represents the text contents of an element or attribute. |
4.6 or later |
Object: Attr
The Attr object represents an attribute in an Element object.
Although Attr objects describe Element objects, they are not actually child nodes of the element they describe. Instead, attributes are treated as properties of elements, and reside outside of the DOM tree. As a result, the Node.parentNode, Node.previousSibling, and Node.nextSibling properties are null for Attr objects.
If a declaration for an attribute exists that defines a default value, but that attribute does not yet exist, the attribute is automatically created and attached to an element with the given value.
Attr properties
|
Property name |
Type |
Description |
Status |
Support level |
Availability |
|---|---|---|---|---|---|
|
name |
DOMString |
Returns the name of the attribute. The value of the name property must be unique across all attributes attached to the same Element node. |
read only |
4.6 or later |
|
|
ownerElement |
Returns the element node that this attribute is attached to. If the attribute is not yet attached to an element, the value of this property is null. |
read only |
4.6 or later |
||
|
specified |
boolean |
When true, this property indicates that the value for the attribute has been explicitly set. If the attribute exists with a default value, this property has a value of false. |
read only |
4.6 or later |
|
|
DOMString |
Specifies the value of the attribute. |
writable |
4.6 or later |
Object: CDATASection
The CDATASection object represents CDATA sections, which escape entire blocks of text, such as XML fragments, source code, or other content that would otherwise be interpreted as XML markup. Only the strings <![CDATA[ (which represents the start of the CDATA section) and ]]> (which represents the end) are parsed.
Although this object inherits from the Node object, Node.normalize() does not merge adjacent CDATASection nodes.
Object: CharacterData
The CharacterData object extends the Node object and can be used to access character data in the DOM. No DOM objects directly correspond to CharacterData; rather, the methods and properties are always inherited by other objects that require this functionality, such as Comment, Text, and CDATASection.
The content of this node is represented as UTF-16. CharacterData methods all work with numeric character offsets and text ranges, and manipulate ranges of text as a sequence of 16-bit units. Before invoking these methods, you should already know the ranges that you are manipulating.
CharacterData properties
|
Property name |
Type |
Description |
Status |
Support level |
Availability |
|---|---|---|---|---|---|
|
DOMString |
Specifies the character data of the current node. |
writable |
4.6 or later |
||
|
length |
int |
Returns the length of the content of the data property or the CharacterData.substringData() method. |
read only |
4.6 or later |
CharacterData methods
|
Method name |
Description |
Support level |
Availability |
|---|---|---|---|
|
appendData() |
Appends the given string to the end of the data of the node. |
4.6 or later |
|
|
deleteData() |
Removes the specified range of data. |
4.6 or later |
|
|
insertData() |
Inserts a string at the specified location in the data. |
4.6 or later |
|
|
replaceData() |
Replaces the specified range of data with the given string. |
4.6 or later |
|
|
Returns the specified range of data from the node. |
4.6 or later |
Object: Comment
The Comment object inherits from the CharacterData object and represents the content of a comment, which begins with <!-- and ends with -->. The contents of this node include any characters that exist between those two markers.
Document properties
|
Property name |
Type |
Description |
Status |
Support level |
Availability |
|---|---|---|---|---|---|
|
defaultView |
AbstractView |
Returns the default view of the document. |
read only |
4.6 or later |
|
|
doctype |
Returns the document type declaration associated with the document. |
read only |
4.6 or later |
||
|
documentElement |
Returns the root element in a document. |
read only |
4.6 or later |
||
|
implementation |
Returns the DOMImplementation object that handles this document. |
read only |
4.6 or later |
||
|
parentWindow |
Returns a reference to the parent window. If no parent window exists, this property points to the current active window. |
read only |
Not defined in any specification. |
4.6 or later |
|
|
styleSheets |
Returns an array of all the style sheets in the document. |
read only |
4.6 or later |
Document methods
|
Method name |
Description |
Support level |
Availability |
|---|---|---|---|
|
adoptNode() |
Adopts a node and its children from an external document to the current document. |
4.7.1 or later |
|
|
createAttribute() |
Creates a new Attr object with the given name. |
4.6 or later |
|
|
createAttributeNS() |
Creates a new Attr object with the given qualified name and namespace URI. |
4.6 or later |
|
|
createCDATASection() |
Creates a new CDATASection object, which represents a block of uninterpreted content. |
4.6 or later |
|
|
createComment() |
Creates a new Comment object with the given text as content. |
4.6 or later |
|
|
createDocumentFragment() |
Creates an empty DocumentFragment object. |
4.6 or later |
|
|
createElement() |
Creates a new Element object of the specified type. |
4.6 or later |
|
|
createElementNS() |
Creates a new Element object of the given qualified name and namespace URI. |
4.6 or later |
|
|
createEntityReference() |
Creates a new EntityReference object with the given name. |
4.6 or later |
|
|
createEvent() |
Creates a new Event object of the given type. |
4.6 or later |
|
|
createNodeIterator() |
Creates a new NodeIterator object, which you can use to iterate through a set of Document nodes rooted at the given node. |
4.6 or later |
|
|
createProcessingInstruction() |
Creates a new ProcessingInstruction object with the given name and data. |
4.6 or later |
|
|
createRange() |
Creates a new Range object. |
4.7.1 or later |
|
|
createTextNode() |
Creates a new Text node containing the given text. |
4.6 or later |
|
|
createTreeWalker() |
Creates a TreeWalker object, which you can use to traverse the specified document subtree. |
4.6 or later |
|
|
getElementById() |
Returns the element node with the given ID value. |
4.6 or later |
|
|
getElementsByTagName() |
Returns a NodeList object that contains an array of a document’s descendent element nodes with the specified tag name. |
4.6 or later |
|
|
getElementsByTagNameNS() |
Returns a NodeList object that contains an array of a document’s descendent element nodes with the given local name and namespace URI. |
4.6 or later |
|
|
getOverrideStyle() |
Retrieves the override CSSStyleDeclaration object for the given element. |
4.6 or later |
|
|
importNode() |
Imports a node from a different document. |
4.6 or later |
|
|
querySelector() |
Returns the first element within the subtree of the Document node that matches the specified selectors. |
5.0 or later |
|
|
querySelectorAll() |
Finds the elements within the subtree of the Document node that match the specified selectors, and returns them as a NodeList object. |
5.0 or later |
Object: DocumentFragment
The DocumentFragment object is a lightweight Document object, used to create or extract only a portion of a document.
A DocumentFragment behaves like a conventional Node object, except that it does not need to be fully formed.
The Range object uses DocumentFragment objects extensively, so that it can extract and store ranges of DOM nodes without creating an entirely new document.
When the children of a DocumentFragment object are inserted into a Document object, only the children of the DocumentFragment, and not the DocumentFragment itself, are inserted into the node.
DocumentFragment methods
|
Method name |
Description |
Support level |
Availability |
|---|---|---|---|
|
querySelector() |
Returns the first element within the subtree of the DocumentFragment object that matches the specified selectors. |
5.0 or later |
|
|
querySelectorAll() |
Finds the elements within the subtree of the DocumentFragment object that match the specified selectors, and returns them as a NodeList object. |
5.0 or later |
DocumentType properties
|
Property name |
Type |
Description |
Status |
Support level |
Availability |
|---|---|---|---|---|---|
|
entities |
Returns a list of all the general entities defined within the DTD. |
read only |
4.6 or later |
||
|
internalSubset |
DOMString |
Returns the contents of the DTD subset. Contains the string between the “[“ and “]” characters. |
read only |
4.6 or later |
|
|
name |
DOMString |
Returns the name of the DTD. |
read only |
4.6 or later |
|
|
notations |
Returns a list of all the notations defined within the DTD. |
read only |
4.6 or later |
||
|
publicId |
DOMString |
Returns the public identifier of the external subset. |
read only |
4.6 or later |
|
|
systemId |
DOMString |
Returns the system identifier of the external subset. |
read only |
4.6 or later |
Object: DOMException
Object: DOMImplementation
DOMImplementation methods
|
Method name |
Description |
Support level |
Availability |
|---|---|---|---|
|
createCSSStyleSheet() |
Creates a new CSS stylesheet document object. |
4.6 or later |
|
|
createDocument() |
Creates a new XML or HTML document object. |
4.6 or later |
|
|
createDocumentType() |
Creates an empty document type node. |
4.6 or later |
|
|
hasFeature() |
Determines whether the DOM implementation implements a specific feature. |
4.6 or later |
Object: Element
The Element object represents an element in an HTML or XML document. Elements may have attributes associated with them. You can use the Node.attributes property to retrieve a map of all the attributes attached to the element.
This object provides several methods for handling all the available attributes, individual attribute values, or individual Attr objects.
Element properties
Element methods
|
Method name |
Description |
Support level |
Availability |
|---|---|---|---|
|
getAttribute() |
Retrieves the value of the attribute of the given name. |
4.6 or later |
|
|
getAttributeNode() |
Retrieves the attribute node of the given name. |
4.6 or later |
|
|
getAttributeNodeNS() |
Retrieves the attribute node with the given namespace URI and local name. |
4.6 or later |
|
|
getAttributeNS() |
Retrieves the value of the attribute with the given namespace URI and local name. |
4.6 or later |
|
|
getElementsByTagName() |
Returns a NodeList object that contains an array of an element’s descendent element nodes with the specified tag name. |
4.6 or later |
|
|
getElementsByTagNameNS() |
Returns a NodeList object that contains an array of an element’s descendent element nodes with the given local name and namespace URI. |
4.6 or later |
|
|
hasAttribute() |
Determines whether an attribute of the given name is specified on the element. |
4.6 or later |
|
|
hasAttributeNS() |
Determines whether an attribute of the given namespace and local name is specified on the element. |
4.6 or later |
|
|
querySelector() |
Returns the first element within the subtree of the current Element node that matches the specified selectors. |
5.0 or later |
|
|
querySelectorAll() |
Finds elements within the subtree of the current Element that match the specified selectors, and returns them as a NodeList object. |
5.0 or later |
|
|
removeAttribute() |
Removes the attribute of the given name from the element node. |
4.6 or later |
|
|
removeAttributeNode() |
Removes the specified attribute node from the element node. |
4.6 or later |
|
|
removeAttributeNS() |
Removes the attribute node with the given namespace URI and local name from the element node. |
4.6 or later |
|
|
setAttribute() |
Adds a new attribute to an element, and sets it to the given value. |
4.6 or later |
|
|
setAttributeNode() |
Adds a new attribute node to an element. |
4.6 or later |
|
|
setAttributeNodeNS() |
Adds a new attribute node to an element. |
4.6 or later |
|
|
setAttributeNS() |
Adds a new attribute to an element, and sets it to the given value. |
4.6 or later |
Object: Entity
The Entity object represents any entity in an XML document. Entities are declarations of abbreviated text or other nodes within an XML document, which can be inserted at various places in an XML document using EntityReference objects.
The Entity name is stored in the Node.nodeName property. However, the actual content of the entity is contained within the Entity node’s children. An Entity node has no parent; the Node.parentNode property for an entity will always be null.
Entity nodes and their children are read only and can not be modified once they have been added to a document. If you need to change the content of an Entity object, you must create a new one, then update all the EntityReference objects that referred to the old Entity so that they refer to the new Entity instead.
Entity properties
|
Property name |
Type |
Description |
Status |
Support level |
Availability |
|---|---|---|---|---|---|
|
notationName |
DOMString |
The name of the notation for an unparsed entity. For parsed entities, the value of this property is null. |
read only |
4.6 or later |
|
|
publicId |
DOMString |
The public identifier associated with the entity. |
read only |
4.6 or later |
|
|
systemId |
DOMString |
The system identifier associated with this entity. |
read only |
4.6 or later |
Object: EntityReference
The EntityReference object represents references to Entity objects within the document. An EntityReference is a node within the DOM tree that copies the children of the referenced Entity object.
The children of EntityReferences are read only and cannot be modified once they are added to a document.
Object: NamedNodeMap
The NamedNodeMap object represents collections of nodes that can be accessed by name.
You can access an individual node within a collection by its index position using NamedNodeMap.item(), by its name or id attribute using NamedNodeMap.getNamedItem(), or you can index the object directly. For example, if you create an instance of a NamedNodeMap object called myNamedNodeMap, then specifying
NamedNodeMap properties
NamedNodeMap methods
|
Method name |
Description |
Support level |
Availability |
|---|---|---|---|
|
Retrieves the node with the given name. |
DOM 2 Core |
4.6 or later |
|
|
Retrieves the node with the given name and namespace URI. |
DOM 2 Core |
4.6 or later |
|
|
Returns the node at the given index in the map. |
DOM 2 Core |
4.6 or later |
|
|
Removes the node with the given name from the map. |
DOM 2 Core |
4.6 or later |
|
|
Removes the node with the given name and namespace URI from the map. |
DOM 2 Core |
4.6 or later |
|
|
Adds a node using the Node.nodeName attribute. |
DOM 2 Core |
4.6 or later |
|
|
Adds a node using the Node.nodeName attribute and the namespace URI. |
DOM 2 Core |
4.6 or later |
Object: Node
Availability |
|
Extended by |
Attr, CharacterData, Document, DocumentFragment, DocumentType, Element, Entity, EntityReference, Notation, ProcessingInstruction |
The Node object represents a unique node within the DOM tree. It is the primary data type for the DOM.
While Node exposes methods for dealing with children, not all objects inheriting from Node may have children. For example, Text nodes do not permit children; trying to add children to such nodes results in a DOMException being raised.
The Node.nodeName, Node.nodeValue, and Node.nodeType properties enable you to acquire node information without casting down to the specific child object. In cases where there is no obvious mapping of these properties for a specific nodeType (for example, the Node.nodeValue for an Element, or attributes for a Comment), they return null.
The specialized objects may contain additional and more convenient mechanisms to get and set the relevant information.
Node properties
|
Property name |
Type |
Description |
Status |
Support level |
Availability |
|---|---|---|---|---|---|
|
attributes |
Returns a NamedNodeMap object that contains the attributes of the given element node, or null, if the node is not an element. |
read only |
4.6 or later |
||
|
childNodes |
Returns a NodeList object that contains all the child elements of the given node. |
read only |
4.6 or later |
||
|
firstChild |
Returns the first child of the given node. |
read only |
4.6 or later |
||
|
lastChild |
Returns the last child of the given node. |
read only |
4.6 or later |
||
|
localName |
DOMString |
Returns the local part of the qualified name for the given node. |
read only |
4.6 or later |
|
|
namespaceURI |
DOMString |
Returns the namespace URI for the given node, or null if it is not specified. |
read only |
4.6 or later |
|
|
nextSibling |
Returns the node immediately following the given node. |
read only |
4.6 or later |
||
|
nodeName |
DOMString |
Returns the name of the given node. |
read only |
4.6 or later |
|
|
nodeType |
unsigned short |
Returns a code representing the type of the given node. |
read only |
4.6 or later |
|
|
nodeValue |
DOMString |
Specifies the value of the given node. |
writable |
4.6 or later |
|
|
ownerDocument |
Returns the Document object associated with the given node. |
read only |
4.6 or later |
||
|
parentNode |
Returns the parent of the given node. |
read only |
4.6 or later |
||
|
prefix |
DOMString |
Specifies the prefix, extracted from the qualified name of the given node, or null if it is unspecified. |
writable |
4.6 or later |
|
|
previousSibling |
Returns the node immediately preceding the current node. |
read only |
4.6 or later |
Node methods
|
Method name |
Description |
Support level |
Availability |
|---|---|---|---|
|
addEventListener() |
Adds an EventListener object to a set of event listeners for the given node. |
4.6 or later |
|
|
appendChild() |
Adds a node to the end of the array of child nodes for the given node. |
4.6 or later |
|
|
cloneNode() |
Returns a duplicate of the given node. The duplicate node has no parent. |
4.6 or later |
|
|
dispatchEvent() |
Dispatches an Event object. |
4.6 or later |
|
|
hasAttributes() |
Returns whether the given node has any attributes. |
4.6 or later |
|
|
hasChildNodes() |
Returns whether the given node has any children. |
4.6 or later |
|
|
insertBefore() |
Inserts a new node before the given node. |
4.6 or later |
|
|
isSupported() |
Tests whether the given node supports a specific feature. |
4.6 or later |
|
|
normalize() |
Merges text nodes adjacent to the given element node to create a normalized DOM. |
4.6 or later |
|
|
removeChild() |
Removes the specified child from the given element node and returns it. |
4.6 or later |
|
|
removeEventListener() |
Removes an event listener from an EventTarget. |
4.6 or later |
|
|
replaceChild() |
Removes the specified child from the given and replaces it with another node, then returns the removed node. |
4.6 or later |
Object: NodeList
The NodeList object is an array that contains an ordered collection of nodes.
You can access an individual Node within a collection by its index position using NodeList.item() or you can index the object directly. For example, if you create an instance of a NodeList object called myNodeList, then specifying
myNodelist.item(2)
is equivalent to specifying
myNodelist[2]
NodeList properties
|
Property name |
Type |
Description |
Status |
Support level |
Availability |
|---|---|---|---|---|---|
|
length |
unsigned long |
Returns the number of Nodes in the list. |
read only |
4.6 or later |
NodeList methods
|
Method name |
Description |
Support level |
Availability |
|---|---|---|---|
|
item() |
Returns the Node at the specified index in the collection. |
4.6 or later |
Object: Notation
The Notation object represents a notation declared in a DTD. A Notation declares the format of an unparsed entity, or is used to formally declare ProcessingInstruction targets.
The Node.nodeName property is set to the declared name of the Notation.
Notation properties
|
Property name |
Type |
Description |
Status |
Support level |
Availability |
|---|---|---|---|---|---|
|
publicId |
DOMString |
Returns the public identifier of the Notation, or null if no identifier has been specified. |
read only |
4.6 or later |
|
|
systemId |
DOMString |
Returns the system identifier of the Notation, or null if no identifier has been specified. |
read only |
4.6 or later |
Object: ProcessingInstruction
The ProcessingInstruction object represents a Processing Instruction for an XML document, which enables you to keep processor-specific information within the context of the document. Processing instructions are specified within the <? and ?> markers.
For instance, instructions on which style sheets to apply can be defined in a processing instruction, even though that is not directly related to the content of the document.
ProcessingInstruction properties
|
Property name |
Type |
Description |
Status |
Support level |
Availability |
|---|---|---|---|---|---|
|
data |
DOMString |
Specifies the content of the processing instruction. This content includes everything contained between the processing instruction markers. |
writable |
4.6 or later |
|
|
sheet |
DOMString |
Returns the style sheet associated with the processing instruction. |
read only |
4.6 or later |
|
|
target |
DOMString |
Returns the target of the processing instruction. |
read only |
4.6 or later |
Object: Text
The Text object represents the textual content of an element or attribute. If an element contains no child elements, any text is contained in a single text node in the DOM.
Although it is possible to place multiple text objects are adjacent to one another in a document, adjacent text nodes have no meaning in a document. Hence, using Text.splitText() has no visual effect on the document unless one of the nodes is wrapped by an element.