DOM operations only raise exceptions in "exceptional" circumstances, i.e., when an operation is impossible to perform (either for logical reasons, because data is lost, or because the implementation has become unstable). In general, DOM methods return specific error values in ordinary processing situation, such as out-of-bound errors when usingNodeList
.
Implementations may raise other exceptions under other circumstances. For example, implementations may raise an implementation-dependent exception if anull
argument is passed.
Some languages and object systems do not support the concept of exceptions. For such systems, error conditions may be indicated using native error reporting mechanisms. For some bindings, for example, methods may return error codes similar to those listed in the corresponding method descriptions.
An integer indicating the type of error generated.
If index or size is negative, or greater than the allowed value
If the specified range of text does not fit into a DOMString
If any node is inserted somewhere it doesn't belong
If a node is used in a different document than the one that created it (that doesn't support it)
If an invalid character is specified, such as in a name.
If data is specified for a node which does not support data
If an attempt is made to modify an object where modifications are not allowed
If an attempt was made to reference a node in a context where it does not exist
If the implementation does not support the type of object requested
If an attempt is made to add an attribute that is already inuse elsewhere
TheDOMImplementation
interface provides a number of methods for performing operations that are independent of any particular instance of the document object model.
The DOM Level 1 does not specify a way of creating a document instance, and hence document creation is an operation specific to an implementation. Future Levels of the DOM specification are expected to provide methods for creating documents directly.
Test if the DOM implementation implements a specific feature.
The package name of the feature to test. In Level 1, the legal values are "HTML" and "XML" (case-insensitive).
This is the version number of the package name to test. In Level 1, this is the string "1.0". If the version is not specified, supporting any version of the feature will cause the method to returntrue
.
true
if the feature is implemented in the specified version,false
otherwise.
DocumentFragment
is a "lightweight" or "minimal"Document
object. It is very common to want to be able to extract a portion of a document's tree or to create a new fragment of a document. Imagine implementing a user command like cut or rearranging a document by moving fragments around. It is desirable to have an object which can hold such fragments and it is quite natural to use a Node for this purpose. While it is true that aDocument
object could fulfil this role, aDocument
object can potentially be a heavyweight object, depending on the underlying implementation. What is really needed for this is a very lightweight object.DocumentFragment
is such an object.
Furthermore, various operations -- such as inserting nodes as children of anotherNode
-- may takeDocumentFragment
objects as arguments; this results in all the child nodes of theDocumentFragment
being moved to the child list of this node.
The children of aDocumentFragment
node are zero or more nodes representing the tops of any sub-trees defining the structure of the document.DocumentFragment
nodes do not need to be well-formed XML documents (although they do need to follow the rules imposed upon well-formed XML parsed entities, which can have multiple top nodes). For example, aDocumentFragment
might have only one child and that child node could be aText
node. Such a structure model represents neither an HTML document nor a well-formed XML document.
When aDocumentFragment
is inserted into aDocument
(or indeed any otherNode
that may take children) the children of theDocumentFragment
and not theDocumentFragment
itself are inserted into theNode
. This makes theDocumentFragment
very useful when the user wishes to create nodes that are siblings; theDocumentFragment
acts as the parent of these nodes so that the user can use the standard methods from theNode
interface, such asinsertBefore()
andappendChild()
.
TheDocument
interface represents the entire HTML or XML document. Conceptually, it is the root of the document tree, and provides the primary access to the document's data.
Since elements, text nodes, comments, processing instructions, etc. cannot exist outside the context of aDocument
, theDocument
interface also contains the factory methods needed to create these objects. TheNode
objects created have aownerDocument
attribute which associates them with theDocument
within whose context they were created.
The Document Type Declaration (seeDocumentType
) associated with this document. For HTML documents as well as XML documents without a document type declaration this returnsnull
. The DOM Level 1 does not support editing the Document Type Declaration, thereforedocType
cannot be altered in any way.
TheDOMImplementation
object that handles this document. A DOM application may use objects from multiple implementations.
This is a convenience attribute that allows direct access to the child node that is the root element of the document. For HTML documents, this is the element with the tagName "HTML".
Creates an element of the type specified. Note that the instance returned implements the
The name of the element type to instantiate. For XML, this is case-sensitive. For HTML, thetagName
parameter may be provided in any case, but it must be mapped to the canonical uppercase form by the DOM implementation.
A newElement
object.
INVALID_CHARACTER_ERR: Raised if the specified name contains an invalid character.
Creates an emptyDocumentFragment
object.
A newDocumentFragment
.
Creates aText
node given the specified string.
The data for the node.
The newText
object.
Creates aComment
node given the specified string.
The data for the node.
The newComment
object.
Creates aCDATASection
node whose value is the specified string.
The data for theCDATASection
contents.
The newCDATASection
object.
NOT_SUPPORTED_ERR: Raised if this document is an HTML document.
Creates aProcessingInstruction
node given the specified name and data strings.
The target part of the processing instruction.
The data for the node.
The newProcessingInstruction
object.
INVALID_CHARACTER_ERR: Raised if an invalid character is specified.
NOT_SUPPORTED_ERR: Raised if this document is an HTML document.
Creates anAttr
of the given name. Note that theAttr
instance can then be set on anElement
using thesetAttribute
method.
The name of the attribute.
A newAttr
object.
INVALID_CHARACTER_ERR: Raised if the specified name contains an invalid character.
Creates an EntityReference object.
The name of the entity to reference.
The newEntityReference
object.
INVALID_CHARACTER_ERR: Raised if the specified name contains an invalid character.
NOT_SUPPORTED_ERR: Raised if this document is an HTML document.
Returns aNodeList
of all theElement
s with a given tag name in the order in which they would be encountered in a preorder traversal of theDocument
tree.
The name of the tag to match on. The special value "*" matches all tags.
A newNodeList
object containing all the matchedElement
s.
TheNode
interface is the primary datatype for the entire Document Object Model. It represents a single node in the document tree. While all objects implementing theNode
interface expose methods for dealing with children, not all objects implementing theNode
interface may have children. For example,Text
nodes may not have children, and adding children to such nodes results in aDOMException
being raised.
The attributesnodeName
,nodeValue
andattributes
are included as a mechanism to getat node information without casting down to the specific derived interface. In cases where there is no obvious mapping of these attributes for a specificnodeType
(e.g.,nodeValue
for an Element orattributes
for a Comment), this returnsnull
. Note that the specialized interfaces may contain additional and more convenient mechanisms to get and set the relevant information.
An integer indicating which type of node this is.
The node is aElement
.
The node is anAttr
.
The node is aText
node.
The node is aCDATASection
.
The node is anEntityReference
.
The node is anEntity
.
The node is aProcessingInstruction
.
The node is aComment
.
The node is aDocument
.
The node is aDocumentType
.
The node is aDocumentFragment
.
The node is aNotation
.
The values ofnodeName
,nodeValue
, andattributes
vary according to the node type as follows:
nodeName | nodeValue | attributes | |
Element | tagName | null | NamedNodeMap |
Attr | name of attribute | value of attribute | null |
Text | #text | content of the text node | null |
CDATASection | #cdata-section | content of the CDATA Section | null |
EntityReference | name of entity referenced | null | null |
Entity | entity name | null | null |
ProcessingInstruction | target | entire content excluding the target | null |
Comment | #comment | content of the comment | null |
Document | #document | null | null |
DocumentType | document type name | null | null |
DocumentFragment | #document-fragment | null | null |
Notation | notation name | null | null |
The name of this node, depending on its type; see the table above.
The value of this node, depending on its type; see the table above.
NO_MODIFICATION_ALLOWED_ERR: Raised when the node is readonly.
DOMSTRING_SIZE_ERR: Raised when it would return more characters than fit in aDOMString
variable on the implementation platform.
A code representing the type of the underlying object, as defined above.
The parent of this node. All nodes, exceptDocument
,DocumentFragment
, andAttr
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 isnull
.
ANodeList
that contains all children of this node. If there are no children, this is aNodeList
containing no nodes. The content of the returnedNodeList
is "live" in the sense that, for instance, changes to the children of the node object that it was created from are immediately reflected in the nodes returned by theNodeList
accessors; it is not a static snapshot of the content of the node. This is true for everyNodeList
, including the ones returned by thegetElementsByTagName
method.
The first child of this node. If there is no such node, this returnsnull
.
The last child of this node. If there is no such node, this returnsnull
.
The node immediately preceding this node. If there is no such node, this returnsnull
.
The node immediately following this node. If there is no such node, this returnsnull
.
ANamedNodeMap
containing the attributes of this node (if it is anElement
) ornull
otherwise.
TheDocument
object associated with this node. This is also theDocument
object used to create new nodes. When this node is aDocument
this isnull
.
Inserts the nodenewChild
before the existing child noderefChild
. IfrefChild
isnull
, insertnewChild
at the end of the list of children.
IfnewChild
is aDocumentFragment
object, all of its children are inserted, in the same order, beforerefChild
. If thenewChild
is already in the tree, it is first removed.
The node to insert.
The reference node, i.e., the node before which the new node must be inserted.
The node being inserted.
HIERARCHY_REQUEST_ERR: Raised if this node is of a type that does not allow children of the type of thenewChild
node, or if the node to insert is one of this node's ancestors.
WRONG_DOCUMENT_ERR: Raised ifnewChild
was created from a different document than the one that created this node.
NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
NOT_FOUND_ERR: Raised ifrefChild
is not a child of this node.
Replaces the child nodeoldChild
withnewChild
in the list of children, and returns theoldChild
node. If thenewChild
is already in the tree, it is first removed.
The new node to put in the child list.
The node being replaced in the list.
The node replaced.
HIERARCHY_REQUEST_ERR: Raised if this node is of a type that does not allow children of the type of thenewChild
node, or it the node to put in is one of this node's ancestors.
WRONG_DOCUMENT_ERR: Raised ifnewChild
was created from a different document than the one that created this node.
NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
NOT_FOUND_ERR: Raised ifoldChild
is not a child of this node.
Removes the child node indicated byoldChild
from the list of children, and returns it.
The node being removed.
The node removed.
NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
NOT_FOUND_ERR: Raised ifoldChild
is not a child of this node.
Adds the nodenewChild
to the end of the list of children of this node. If thenewChild
is already in the tree, it is first removed.
The node to add.
If it is aDocumentFragment
object, the entire contents of the document fragment are moved into the child list of this node
The node added.
HIERARCHY_REQUEST_ERR: Raised if this node is of a type that does not allow children of the type of thenewChild
node, or if the node to append is one of this node's ancestors.
WRONG_DOCUMENT_ERR: Raised ifnewChild
was created from a different document than the one that created this node.
NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
This is a convenience method to allow easy determination of whether a node has any children.
true
if the node has any children,false
if the node has no children.
Returns a duplicate of this node, i.e., serves as a generic copy constructor for nodes. The duplicate node has no parent (parentNode
returnsnull
.).
Cloning anElement
copies all attributes and their values, including those generated by the XML processor to represent defaulted attributes, but this method does not copy any text it contains unless it is a deep clone, since the text is contained in a childText
node. Cloning any other type of node simply returns a copy of this node.
Iftrue
, recursively clone the subtree under the specified node; iffalse
, clone only the node itself (and its attributes, if it is anElement
).
The duplicate node.
TheNodeList
interface provides the abstraction of an ordered collection of nodes, without defining or constraining how this collection is implemented.
The items in theNodeList
are accessible via an integral index, starting from 0.
Returns theindex
th item in the collection. Ifindex
is greater than or equal to the number of nodes in the list, this returnsnull
.
Index into the collection.
The node attheindex
th position in theNodeList
, ornull
if that is not a valid index.
The number of nodes in the list. The range of valid child node indices is 0 tolength-1
inclusive.
Objects implementing theNamedNodeMap
interface are used to represent collections of nodes that can be accessed by name. Note thatNamedNodeMap
does not inherit fromNodeList
;NamedNodeMap
s are not maintained in any particular order. Objects contained in an object implementingNamedNodeMap
may also be accessed by an ordinal index, but this is simply to allow convenient enumeration of the contents of aNamedNodeMap
, and does not imply that the DOM specifies an order to these Nodes.
Retrieves a node specified by name.
Name of a node to retrieve.
ANode
(of any type) with the specified name, ornull
if the specified name did not identify any node in the map.
Adds a node using itsnodeName
attribute.
As thenodeName
attribute is used to derive the name which the node must be stored under, multiple nodes of certain types (those that have a "special" string value) cannot be stored as the names would clash. This is seen as preferable to allowing nodes to be aliased.
A node to store in a named node map. The node will later be accessible using the value of thenodeName
attribute of the node. If a node with that name is already present in the map, it is replaced by the new one.
If the newNode
replaces an existing node with the same name the previously existingNode
is returned, otherwisenull
is returned.
WRONG_DOCUMENT_ERR: Raised ifarg
was created from a different document than the one that created theNamedNodeMap
.
NO_MODIFICATION_ALLOWED_ERR: Raised if thisNamedNodeMap
is readonly.
INUSE_ATTRIBUTE_ERR: Raised ifarg
is anAttr
that is already an attribute of anotherElement
object. The DOM user must explicitly cloneAttr
nodes to re-use them in other elements.
Removes a node specified by name. If the removed node is anAttr
with a default value it is immediately replaced.
The name of a node to remove.
The node removed from the map ornull
if no node with such a name exists.
NOT_FOUND_ERR: Raised if there is no node named name
in this map.
NO_MODIFICATION_ALLOWED_ERR: Raised if this map is readonly.
Returns theindex
th item in the map. Ifindex
is greater than or equal to the number of nodes in the map, this returnsnull
.
Index into the map.
The node at theindex
th position in theNamedNodeMap
, ornull
if that is not a valid index.
The number of nodes in the map. The range of valid child node indices is 0 tolength-1
inclusive.
TheCharacterData
interface extends Node with a set of attributes and methods for accessing character data in the DOM. For clarity this set is defined here rather than on each object that uses these attributes and methods. No DOM objects correspond directly toCharacterData
, thoughText
and others do inherit the interface from it. Alloffset
s in this interface start from 0.
The character data of the node that implements this interface. The DOM implementation may not put arbitrary limits on the amount of data that may be stored in aCharacterData
node. However, implementation limits may mean that the entirety of a node's data may not fit into a singleDOMString
. In such cases, the user may callsubstringData
to retrieve the data in appropriately sized pieces.
NO_MODIFICATION_ALLOWED_ERR: Raised when the node is readonly.
DOMSTRING_SIZE_ERR: Raised when it would return more characters than fit in aDOMString
variable on the implementation platform.
The number of characters that are available throughdata
and thesubstringData
method below. This may have the value zero, i.e.,CharacterData
nodes may be empty.
Extracts a range of data from the node.
Start offset of substring to extract.
The number of characters to extract.
The specified substring. If the sum ofoffset
andcount
exceeds thelength
, then all characters to the end of the data are returned.
INDEX_SIZE_ERR: Raised if the specified offset is negative or greater than the number of characters indata
, or if the specifiedcount
is negative.
DOMSTRING_SIZE_ERR: Raised if the specified range of text does not fit into aDOMString
.
Append the string to the end of the character data of the node. Upon success,data
provides access to the concatenation ofdata
and theDOMString
specified.
TheDOMString
to append.
NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
Insert a string at the specified character offset.
The character offset at which to insert.
TheDOMString
to insert.
INDEX_SIZE_ERR: Raised if the specified offset is negative or greater than the number of characters indata
.
NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
Remove a range of characters from the node. Upon success,data
andlength
reflect the change.
The offset from which to remove characters.
The number of characters to delete. If the sum ofoffset
andcount
exceedslength
then all characters fromoffset
to the end of the data are deleted.
INDEX_SIZE_ERR: Raised if the specified offset is negative or greater than the number of characters indata
, or if the specifiedcount
is negative.
NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
Replace the characters starting at the specified character offset with the specified string.
The offset from which to start replacing.
The number of characters to replace. If the sum ofoffset
andcount
exceedslength
, then all characters to the end of the data are replaced (i.e., the effect is the same as aremove
method call with the same range, followed by anappend
method invocation).
TheDOMString
with which the range must be replaced.
INDEX_SIZE_ERR: Raised if the specified offset is negative or greater than the number of characters indata
, or if the specifiedcount
is negative.
NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
TheAttr
interface represents an attribute in anElement
object. Typically the allowable values for the attribute are defined in a document type definition.
Attr
objects inherit theNode
interface, but since they are not actually child nodes of the element they describe, the DOM does not consider them part of the document tree. Thus, theNode
attributesparentNode
,previousSibling
, andnextSibling
have a null value forAttr
objects. The DOM takes the view that attributes are properties of elements rather than having a separate identity from the elements they are associated with; this should make it more efficient to implement such features as default attributes associated with all elements of a given type. Furthermore,Attr
nodes may not be immediate children of aDocumentFragment
. However, they can be associated withElement
nodes contained within aDocumentFragment
. In short, users and implementors of the DOM need to be aware thatAttr
nodes have some things in common with other objects inheriting theNode
interface, but they also are quite distinct.
The attribute's effective value is determined as follows: if this attribute has been explicitly assigned any value, that value is the attribute's effective value; otherwise, if there is a declaration for this attribute, and that declaration includes a default value, then that default value is the attribute's effective value; otherwise, the attribute does not exist on this element in the structure model until it has been explicitly added. Note that thenodeValue
attribute on theAttr
instance can also be used to retrieve the string version of the attribute's value(s).
In XML, where the value of an attribute can contain entity references, the child nodes of theAttr
node provide a representation in which entity references are not expanded. These child nodes may be eitherText
orEntityReference
nodes. Because the attribute type may be unknown, there are no tokenized attribute values.
Returns the name of this attribute.
If this attribute was explicitly given a value in the original document, this istrue
; otherwise, it isfalse
. Note that the implementation is in charge of this attribute, not the user. If the user changes the value of the attribute (even if it ends up having the same value as the default value) then thespecified
flag is automatically flipped totrue
. To re-specify the attribute as the default value from the DTD, the user must delete the attribute. The implementation will then make a new attribute available withspecified
set tofalse
and the default value (if one exists).
In summary: If the attribute has an assigned value in the document then If the attribute has no assigned value in the document and has a default value in the DTD, then If the attribute has no assigned value in the document and has a value of #IMPLIED in the DTD, then the attribute does not appear in the structure model of the document.specified
istrue
, and the value is the assigned value.specified
isfalse
, and the value is the default value in the DTD.
On retrieval, the value of the attribute is returned as a string. Character and general entity references are replaced with their values.
On setting, this creates aText
node with the unparsed contents of the string.
NO_MODIFICATION_ALLOWED_ERR: Raised when the node is readonly.
By far the vast majority of objects (apart from text) that authors encounter when traversing a document areElement
nodes. Assume the following XML document:
When represented using DOM, the top node is anElement
node for "elementExample", which contains two childElement
nodes, one for "subelement1" and one for "subelement2". "subelement1" contains no child nodes.
Elements may have attributes associated with them; since theElement
interface inherits fromNode
, the genericNode
interface methodgetAttributes
may be used to retrieve the set of all attributes for an element. There are methods on theElement
interface to retrieve either anAttr
object by name or an attribute value by name. In XML, where an attribute value may contain entity references, anAttr
object should be retrieved to examine the possibly fairly complex sub-tree representing the attribute value. On the other hand, in HTML, where all attributes have simple string values, methods to directly access an attribute value can safely be used as a convenience.
The name of the element. For example, in:tagName
has the value"elementExample"
. Note that this is case-preserving in XML, as are all of the operations of the DOM. The HTML DOM returns thetagName
of an HTML element in the canonical uppercase form, regardless of the case in the source HTML document.
Retrieves an attribute value by name.
The name of the attribute to retrieve.
TheAttr
value as a string, or the empty string if that attribute does not have a specified or default value.
Adds a new attribute. If an attribute with that name is already present in the element, its value is changed to be that of the value parameter. This value is a simple string, it is not parsed as it is being set. So any markup (such as syntax to be recognized as an entity reference) is treated as literal text, and needs to be appropriately escaped by the implementation when it is written out. In order to assign an attribute value that contains entity references, the user must create anAttr
node plus anyText
andEntityReference
nodes, build the appropriate subtree, and usesetAttributeNode
to assign it as the value of an attribute.
The name of the attribute to create or alter.
Value to set in string form.
INVALID_CHARACTER_ERR: Raised if the specified name contains an invalid character.
NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
Removes an attribute by name. If the removed attribute has a default value it is immediately replaced.
The name of the attribute to remove.
NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
Retrieves anAttr
node by name.
The name of the attribute to retrieve.
TheAttr
node with the specified attribute name ornull
if there is no such attribute.
Adds a new attribute. If an attribute with that name is already present in the element, it is replaced by the new one.
TheAttr
node to add to the attribute list.
If thenewAttr
attribute replaces an existing attribute with the same name, the previously existingAttr
node is returned, otherwisenull
is returned.
WRONG_DOCUMENT_ERR: Raised ifnewAttr
was created from a different document than the one that created the element.
NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
INUSE_ATTRIBUTE_ERR: Raised ifnewAttr
is already an attribute of anotherElement
object. The DOM user must explicitly cloneAttr
nodes to re-use them in other elements.
Removes the specified attribute.
TheAttr
node to remove from the attribute list. If the removedAttr
has a default value it is immediately replaced.
TheAttr
node that was removed.
NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
NOT_FOUND_ERR: Raised ifoldAttr
is not an attribute of the element.
Returns aNodeList
of all descendant elements with a given tag name, in the order in which they would be encountered in a preorder traversal of theElement
tree.
The name of the tag to match on. The special value "*" matches all tags.
A list of matchingElement
nodes.
Puts allText
nodes in the full depth of the sub-tree underneath thisElement
into a "normal" form where only markup (e.g., tags, comments, processing instructions, CDATA sections, and entity references) separatesText
nodes, i.e., there are no adjacentText
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, and is useful when operations (such as XPointer lookups) that depend on a particular document tree structure are to be used.
TheText
interface represents the textual content (termedElement
orAttr
. If there is no markup inside an element's content, the text is contained in a single object implementing theText
interface that is the only child of the element. If there is markup, it is parsed into a list of elements andText
nodes that form the list of children of the element.
When a document is first made available via the DOM, there is only oneText
node for each block of text. Users may create adjacentText
nodes that represent the contents of a given element without any intervening markup, but should be aware that there is no way to represent the separations between these nodes in XML or HTML, so they will not (in general) persist between DOM editing sessions. Thenormalize()
method onElement
merges any such adjacentText
objects into a single node for each block of text; this is recommended before employing operations that depend on a particular document structure, such as navigation withXPointers.
Breaks thisText
node into two Text nodes at the specified offset, keeping both in the tree as siblings. This node then only contains all the content up to theoffset
point. And a newText
node, which is inserted as the next sibling of this node, contains all the content at and after theoffset
point.
The offset at which to split, starting from 0.
The newText
node.
INDEX_SIZE_ERR: Raised if the specified offset is negative or greater than the number of characters indata
.
NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
This represents the content of a comment, i.e., all the characters between the starting '<!--
' and ending '-->
'. Note that this is the definition of a comment in XML, and, in practice, HTML, although some HTML tools may implement the full SGML comment structure.
CDATA sections are used to escape blocks of text containing characters that would otherwise be regarded as markup. The only delimiter that is recognized in a CDATA section is the "]]>" string that ends the CDATA section. CDATA sections can not be nested. The primary purpose is for including material such as XML fragments, without needing to escape all the delimiters.
TheDOMString
attribute of theText
node holds the text that is contained by the CDATA section. Note that this
TheCDATASection
interface inherits theCharacterData
interface through theText
interface. AdjacentCDATASections
nodes are not merged by use of the Element.normalize() method.
EachDocument
has adoctype
attribute whose value is eithernull
or aDocumentType
object. TheDocumentType
interface in the DOM Level 1 Core provides an interface to the list of entities that are defined for the document, and little else because the effect of namespaces and the various XML scheme efforts on DTD representation are not clearly understood as of this writing.
The DOM Level 1 doesn't support editingDocumentType
nodes.
The name of DTD; i.e., the name immediately following theDOCTYPE
keyword.
ANamedNodeMap
containing the general entities, both external and internal, declared in the DTD. Duplicates are discarded. For example in:foo
andbar
but notbaz
. Every node in this map also implements theEntity
interface.
The DOM Level 1 does not support editing entities, thereforeentities
cannot be altered in any way.
ANamedNodeMap
containing the notations declared in the DTD. Duplicates are discarded. Every node in this map also implements theNotation
interface.
The DOM Level 1 does not support editing notations, thereforenotations
cannot be altered in any way.
This interface represents a notation declared in the DTD. A notation either declares, by name, the format of an unparsed entity (see section 4.7 of the XML 1.0 specification), or is used for formal declaration of Processing Instruction targets (see section 2.6 of the XML 1.0 specification). ThenodeName
attribute inherited fromNode
is set to the declared name of the notation.
The DOM Level 1 does not support editingNotation
nodes; they are therefore readonly.
ANotation
node does not have any parent.
The public identifier of this notation. If the public identifier was not specified, this isnull
.
The system identifier of this notation. If the system identifier was not specified, this isnull
.
This interface represents an entity, either parsed or unparsed, in an XML document. Note that this models the entity itselfEntity
declaration modeling has been left for a later Level of the DOM specification.
ThenodeName
attribute that is inherited fromNode
contains the name of the entity.
An XML processor may choose to completely expand entities before the structure model is passed to the DOM; in this case there will be noEntityReference
nodes in the document tree.
XML does not mandate that a non-validating XML processor read and process entity declarations made in the external subset or declared in external parameter entities. This means that parsed entities declared in the external subset need not be expanded by some classes of applications, and that the replacement value of the entity may not be available. When the replacement value is available, the correspondingEntity
node's child list represents the structure of that replacement text. Otherwise, the child list is empty.
The resolution of the children of theEntity
(the replacement value) may be lazily evaluated; actions by the user (such as calling thechildNodes
method on theEntity
Node) are assumed to trigger the evaluation.
The DOM Level 1 does not support editingEntity
nodes; if a user wants to make changes to the contents of anEntity
, every relatedEntityReference
node has to be replaced in the structure model by a clone of theEntity
's contents, and then the desired changes must be made to each of those clones instead. All the descendants of anEntity
node are readonly.
AnEntity
node does not have any parent.
The public identifier associated with the entity, if specified. If the public identifier was not specified, this isnull
.
The system identifier associated with the entity, if specified. If the system identifier was not specified, this isnull
.
For unparsed entities, the name of the notation for the entity. For parsed entities, this isnull
.
EntityReference
objects may be inserted into the structure model when an entity reference is in the source document, or when the user wishes to insert an entity reference. Note that character references and references to predefined entities are considered to be expanded by the HTML or XML processor so that characters are represented by their Unicode equivalent rather than by an entity reference. Moreover, the XMLprocessor may completely expand references to entities while building the structure model, instead of providingEntityReference
objects. If it does provide such objects, then for a givenEntityReference
node, it may be that there is noEntity
node representing the referenced entity; but if such anEntity
exists, then the child list of theEntityReference
node is the same as that of theEntity
node. As with theEntity
node, all descendants of theEntityReference
are readonly.
The resolution of the children of theEntityReference
(the replacement value of the referencedEntity
) may be lazily evaluated; actions by the user (such as calling thechildNodes
method on theEntityReference
node) are assumed to trigger the evaluation.
TheProcessingInstruction
interface represents a "processing instruction", used in XML as a way to keep processor-specific information in the text of the document.
The target of this processing instruction. XML defines this as being the first token following the markup that begins the processing instruction.
The content of this processing instruction. This is from the first non white space character after the target to the character immediately preceding the?>
.
NO_MODIFICATION_ALLOWED_ERR: Raised when the node is readonly.
AnHTMLCollection
is a list of nodes. An individual node may be accessed by either ordinal index or the node'sname
orid
attributes.
This attribute specifies the length or
This method retrieves a node specified by ordinal index. Nodes are numbered in tree order (depth-first traversal order).
The index of the node to be fetched. The index origin is 0.
TheNode
at the corresponding position upon success. A value ofnull
is returned if the index is out of range.
This method retrieves aNode
using a name. It first searches for aNode
with a matchingid
attribute. If it doesn't find one, it then searches for aNode
with a matchingname
attribute, but only on those elements that are allowed a name attribute.
The name of theNode
to be fetched.
TheNode
with aname
orid
attribute whose value corresponds to the specified string. Upon failure (e.g., no node with this name exists), returnsnull
.
AnHTMLDocument
is the root of the HTML hierarchy and holds the entire content. Beside providing access to the hierarchy, it also provides some convenience methods for accessing certain sets of information from the document.
The following properties have been deprecated in favor of the corresponding ones for the BODY element:
alinkColor
background
bgColor
fgColor
linkColor
vlinkColor
The title of a document as specified by theTITLE
element in the head of the document.
Returns the URI of the page that linked to this page. The value is an empty string if the user navigated to the page directly (not through a link, but, for example, via a bookmark).
The domain name of the server that served the document, or a null string if the server cannot be identified by a domain name.
The complete URI of the document.
The element that contains the content for the document. In documents withBODY
contents, returns theBODY
element, and in frameset documents, this returns the outermostFRAMESET
element.
A collection of all theIMG
elements in a document. The behavior is limited toIMG
elements for backwards compatibility.
A collection of all theOBJECT
elements that include applets andAPPLET
(
A collection of allAREA
elements and anchor (A
) elements in a document with a value for thehref
attribute.
A collection of all the forms of a document.
A collection of all the anchor (A
) elements in a document with a value for thename
attribute.name
attribute, not those created with theid
attribute.
The cookies associated with this document. If there are none, the value is an empty string. Otherwise, the value is a string: a semicolon-delimited list of "name, value" pairs for all the cookies associated with the page. For example,name=value;expires=date
.
Open a document stream for writing. If a document exists in the target, this method clears it.
Closes a document stream opened byopen()
and forces rendering.
Write a string of text to a document stream opened byopen()
. The text is parsed into the document's structure model.
The string to be parsed into some structure in the document structure model.
Write a string of text followed by a newline character to a document stream opened byopen()
. The text is parsed into the document's structure model.
The string to be parsed into some structure in the document structure model.
Returns the Element whoseid
is given by elementId. If no such element exists, returnsnull
. Behavior is not defined if more than one element has thisid
.
The uniqueid
value for an element.
The matching element.
Returns the (possibly empty) collection of elements whosename
value is given byelementName
.
Thename
attribute value for an element.
The matching elements.
All HTML element interfaces derive from this class. Elements that only expose the HTML core attributes are represented by the baseHTMLElement
interface. These elements are as follows:
HEAD
special: SUB, SUP, SPAN, BDO
font: TT, I, B, U, S, STRIKE, BIG, SMALL
phrase: EM, STRONG, DFN, CODE, SAMP, KBD, VAR, CITE, ACRONYM, ABBR
list: DD, DT
NOFRAMES, NOSCRIPT
ADDRESS, CENTER
style
attribute for this interface is reserved for future usage.
The element's identifier. See the
The element's advisory title. See the
Language code defined in RFC 1766. See the
Specifies the base direction of directionally neutral text and the directionality of tables. See the
The class attribute of the element. This attribute has been renamed due to conflicts with the "class" keyword exposed by many languages. See the
Root of an HTML document. See the
Version information about the document's DTD. See the
Document head information. See the
URI designating a metadata profile. See the
TheLINK
element specifies a link to an external resource, and defines this document's relationship to that resource (or vice versa). See the
Enables/disables the link. This is currently only used for style sheet links, and may be used to activate or deactivate style sheets.
The character encoding of the resource being linked to. See the
The URI of the linked resource. See the
Language code of the linked resource. See the
Designed for use with one or more target media. See the
Forward link type. See the
Reverse link type. See the
Frame to render the resource in. See the
Advisory content type. See the
The document title. See the
The specified title as a string.
This contains generic meta-information about the document. See the
Associated information. See the
HTTP response header name. See the
Meta information name. See the
Select form of content. See the
Document base URI. See the
The base URI See the
The default target frame. See the
This element is used for single-line text input. See the
Returns theFORM
element containing this control. Returns null if this control is not within the context of a form.
The prompt message. See the
Style information. A more detailed style sheet object model is planned to be defined in a separate document. See the
Enables/disables the style sheet.
Designed for use with one or more target media. See the
The style sheet language (Internet media type). See the
The HTML document body. This element is always present in the DOM API, even if the tags are not present in the source document. See the
Color of active links (after mouse-button down, but before mouse-button up). See the
URI of the background texture tile image. See the
Document background color. See the
Color of links that are not active and unvisited. See the
Document text color. See the
Color of links that have been visited by the user. See the
TheFORM
element encompasses behavior similar to a collection and an element. It provides direct access to the contained input elements as well as the attributes of the form element. See the
Returns a collection of all control elements in the form.
The number of form controls in the form.
Names the form.
List of character sets supported by the server. See the
Server-side form handler. See the
The content type of the submitted form, generally "application/x-www-form-urlencoded". See the
HTTP method used to submit form. See the
Frame to render the resource in. See the
Submits the form. It performs the same action as a submit button.
Restores a form element's default values. It performs the same action as a reset button.
The select element allows the selection of an option. The contained options can be directly accessed through the select element as a collection. See the
The type of control created.
The ordinal index of the selected option. The value -1 is returned if no element is selected. If multiple options are selected, the index of the first selected option is returned.
The current form control value.
The number of options in thisSELECT
.
Returns theFORM
element containing this control. Returns null if this control is not within the context of a form.
The collection ofOPTION
elements contained by this element.
The control is unavailable in this context. See the
If true, multipleOPTION
elements may be selected in thisSELECT
. See the
Form control or object name when submitted with a form. See the
Number of visible rows. See the
Index that represents the element's position in the tabbing order. See the
Add a new element to the collection ofOPTION
elements for thisSELECT
.
The element to add.
The element to insert before, or NULL for the head of the list.
Remove an element from the collection ofOPTION
elements for thisSELECT
. Does nothing if no element has the given index.
The index of the item to remove.
Removes keyboard focus from this element.
Gives keyboard focus to this element.
Group options together in logical subdivisions. See the
The control is unavailable in this context. See the
Assigns a label to this option group. See the
A selectable choice. See the
Returns theFORM
element containing this control. Returns null if this control is not within the context of a form.
Stores the initial value of theselected
attribute.
The text contained within the option element.
The index of thisOPTION
in its parentSELECT
.
The control is unavailable in this context. See the
Option label for use in hierarchical menus. See the
Means that this option is initially selected. See the
The current form control value. See the
Form control.
Stores the initial control value (i.e., the initial value ofvalue
).
Whentype
has the value "Radio" or "Checkbox", stores the initial value of thechecked
attribute.
Returns theFORM
element containing this control. Returns null if this control is not within the context of a form.
A comma-separated list of content types that a server processing this form will handle correctly. See the
A single character access key to give access to the form control. See the
Aligns this object (vertically or horizontally) with respect to its surrounding text. See the
Alternate text for user agents not rendering the normal content of this element. See the
Describes whether a radio or check box is checked, whentype
has the value "Radio" or "Checkbox". The value is TRUE if explicitly set. Represents the current state of the checkbox or radio button. See the
The control is unavailable in this context. See the
Maximum number of characters for text fields, whentype
has the value "Text" or "Password". See the
Form control or object name when submitted with a form. See the
This control is read-only. Whentype
has the value "text" or "password" only. See the
Size information. The precise meaning is specific to each type of field. See the
When thetype
attribute has the value "Image", this attribute specifies the location of the image to be used to decorate the graphical submit button. See the
Index that represents the element's position in the tabbing order. See the
The type of control created. See the
Use client-side image map. See the
The current form control value. Used for radio buttons and check boxes. See the
Removes keyboard focus from this element.
Gives keyboard focus to this element.
Select the contents of the text area. ForINPUT
elements whosetype
attribute has one of the following values: "Text", "File", or "Password".
Simulate a mouse-click. ForINPUT
elements whosetype
attribute has one of the following values: "Button", "Checkbox", "Radio", "Reset", or "Submit".
Multi-line text field. See the
Stores the initial control value (i.e., the initial value ofvalue
).
Returns theFORM
element containing this control. Returns null if this control is not within the context of a form.
A single character access key to give access to the form control. See the
Width of control (in characters). See the
The control is unavailable in this context. See the
Form control or object name when submitted with a form. See the
This control is read-only. See the
Number of text rows. See the
Index that represents the element's position in the tabbing order. See the
The type of this form control.
The current textual content of the multi-line text field. If the entirety of the data can not fit into a single wstring, the implementation may truncate the data.
Removes keyboard focus from this element.
Gives keyboard focus to this element.
Select the contents of theTEXTAREA
.
Push button. See the
Returns theFORM
element containing this control. Returns null if this control is not within the context of a form.
A single character access key to give access to the form control. See the
The control is unavailable in this context. See the
Form control or object name when submitted with a form. See the
Index that represents the element's position in the tabbing order. See the
The type of button. See the
The current form control value. See the
Form field label text. See the
Returns theFORM
element containing this control. Returns null if this control is not within the context of a form.
A single character access key to give access to the form control. See the
This attribute links this label with another form control byid
attribute. See the
Organizes form controls into logical groups. See the
Returns theFORM
element containing this control. Returns null if this control is not within the context of a form.
Provides a captionfor aFIELDSET
grouping. See the
Returns theFORM
element containing this control. Returns null if this control is not within the context of a form.
A single character access key to give access to the form control. See the
Text alignment relative toFIELDSET
. See the
Unordered list. See the
Reduce spacing between list items. See the
Bullet style. See the
Ordered list. See the
Reduce spacing between list items. See the
Starting sequence number. See the
Numbering style. See the
Definition list. See the
Reduce spacing between list items. See the
Directory list. See the
Reduce spacing between list items. See the
Menu list. See the
Reduce spacing between list items. See the
List item. See the
List item bullet style. See the
Reset sequence number when used inOL
See the
Generic block container. See the
Horizontal text alignment. See the
Paragraphs. See the
Horizontal text alignment. See the
For theH1
toH6
elements. See the
Horizontal text alignment. See the
For theQ
andBLOCKQUOTE
elements. See the
A URI designating a document that designates a source document or message. See the
Preformatted text. See the
Fixed width for content. See the
Force a line break. See the
Control flow of text around floats. See the
Base font. See the
Font color. See the
Font face identifier. See the
Font size. See the
Local change to font. See the
Font color. See the
Font face identifier. See the
Font size. See the
Create a horizontal rule. See the
Align the rule on the page. See the
Indicates to the user agent that there should be no shading in the rendering of this element. See the
The height of the rule. See the
The width of the rule. See the
Notice of modification to part of a document. See the
A URI designating a document that describes the reason for the change. See the
The date and time of the change. See the
The anchor element. See the
A single character access key to give access to the form control. See the
The character encoding of the linked resource. See the
Comma-separated list of lengths, defining an active region geometry. See alsoshape
for the shape of the region. See the
The URI of the linked resource. See the
Language code of the linked resource. See the
Anchor name. See the
Forward link type. See the
Reverse link type. See the
The shape of the active area. The coordinates are given bycoords
. See the
Index that represents the element's position in the tabbing order. See the
Frame to render the resource in. See the
Advisory content type. See the
Removes keyboard focus from this element.
Gives keyboard focus to this element.
Embedded image. See the
URI designating the source of this image, for low-resolution output.
The name of the element (for backwards compatibility).
Aligns this object (vertically or horizontally) with respect to its surrounding text. See the
Alternate text for user agents not rendering the normal content of this element. See the
Width of border around image. See the
Override height. See the
Horizontal space to the left and right of this image. See the
Use server-side image map. See the
URI designating a long description of this image or frame. See the
URI designating the source of this image. See the
Use client-side image map. See the
Vertical space above and below this image. See the
Override width. See the
Generic embedded object.
Returns theFORM
element containing this control. Returns null if this control is not within the context of a form.
Applet class file. See thecode
attribute for HTMLAppletElement.
Aligns this object (vertically or horizontally) with respect to its surrounding text. See the
Space-separated list of archives. See the
Width of border around the object. See the
Base URI forclassid
,data
, andarchive
attributes. See the
Content type for data downloaded viaclassid
attribute. See the
A URI specifying the location of the object's data. See the
Declare (for future reference), but do not instantiate, this object. See the
Override height. See the
Horizontal space to the left and right of this image, applet, or object. See the
Form control or object name when submitted with a form. See the
Message to render while loading the object. See the
Index that represents the element's position in the tabbing order. See the
Content type for data downloaded viadata
attribute. See the
Use client-side image map. See the
Vertical space above and below this image, applet, or object. See the
Override width. See the
Parameters fed to theOBJECT
element. See the
The name of a run-time parameter. See the
Content type for thevalue
attribute whenvaluetype
has the value "ref". See the
The value of a run-time parameter. See the
Information about the meaning of thevalue
attribute value. See the
An embedded Java applet. See the
Aligns this object (vertically or horizontally) with respect to its surrounding text. See the
Alternate text for user agents not rendering the normal content of this element. See the
Comma-separated archive list. See the
Applet class file. See the
Optional base URI for applet. See the
Override height. See the
Horizontal space to the left and right of this image, applet, or object. See the
The name of the applet. See the
Serialized applet file. See the
Vertical space above and below this image, applet, or object. See the
Override width. See the
Client-side image map. See the
The list of areas defined for the image map.
Names the map (for use withusemap
). See the
Client-side image map area definition. See the
A single character access key to give access to the form control. See the
Alternate text for user agents not rendering the normal content of this element. See the
Comma-separated list of lengths, defining an active region geometry. See alsoshape
for the shape of the region. See the
The URI of the linked resource. See the
Specifies that this area is inactive, i.e., has no associated action. See the
The shape of the active area. The coordinates are given bycoords
. See the
Index that represents the element's position in the tabbing order. See the
Frame to render the resource in. See the
Script statements. See the
The script content of the element.
The character encoding of the linked resource. See the
Indicates that the user agent can defer processing of the script. See the
URI designating an external script. See the
The content type of the script language. See the
The create* and delete* methods on the table allow authors to construct and modify tables. HTML 4.0 specifies that only one of each of theCAPTION
,THEAD
, andTFOOT
elements may exist in a table. Therefore, if one exists, and the createTHead() or createTFoot() method is called, the method returns the existing THead or TFoot element. See the
Returns the table'sCAPTION
, or void if none exists.
Returns the table'sTHEAD
, ornull
if none exists.
Returns the table'sTFOOT
, ornull
if none exists.
Returns a collection of all the rows in the table, including all inTHEAD
,TFOOT
, allTBODY
elements.
Returns a collection of the defined table bodies.
Specifies the table's position with respect to the rest of the document. See the
Cell background color. See the
The width of the border around the table. See the
Specifies the horizontal and vertical space between cell content and cell borders. See the
Specifies the horizontal and vertical separation between cells. See the
Specifies which external table borders to render. See the
Specifies which internal table borders to render. See the
Supplementary description about the purpose or structure of a table. See the
Specifies the desired table width. See the
Create a table header row or return an existing one.
A new table header element (THEAD
).
Delete the header from the table, if one exists.
Create a table footer row or return an existing one.
A footer element (TFOOT
).
Delete the footer from the table, if one exists.
Create a new table caption object or return an existing one.
ACAPTION
element.
Delete the table caption, if one exists.
Insert a new empty row in the table.
The row number where to insert a new row.
The newly created row.
Delete a table row.
The index of the row to be deleted.
Table caption See the
Caption alignment with respect to the table. See the
Regroups theCOL
andCOLGROUP
elements. See the
Horizontal alignment of cell data in column. See the
Alignment character for cells in a column. See the
Offset of alignment character. See the
Indicates the number of columns in a group or affected by a grouping. See the
Vertical alignment of cell data in column. See the
Default column width. See the
TheTHEAD
,TFOOT
, andTBODY
elements.
Horizontal alignment of data in cells. See thealign
attribute for HTMLTheadElement for details.
Alignment character for cells in a column. See the
Offset of alignment character. See the
Vertical alignment of data in cells. See thevalign
attribute for HTMLTheadElement for details.
The collection of rows in this table section.
Insert a row into this section.
The row number where to insert a new row.
The newly created row.
Delete a row from this section.
The index of the row to be deleted.
A row in a table. See the
The index of this row, relative to the entire table.
The index of this row, relative to the current section (THEAD
,TFOOT
, orTBODY
).
The collection of cells in this row.
Horizontal alignment of data within cells of this row. See the
Background color for rows. See the
Alignment character for cells in a column. See the
Offset of alignment character. See the
Vertical alignment of data within cells of this row. See the
Insert an emptyTD
cell into this row.
The place to insert the cell.
The newly created cell.
Delete a cell from the current row.
The index of the cell to delete.
The object used to represent theTH
andTD
elements. See the
The index of this cell in the row.
Abbreviation for header cells. See the
Horizontal alignment of data in cell. See the
Names group of related headers. See the
Cell background color. See the
Alignment character for cells in a column. See the
Offset of alignment character. See the
Number of columns spanned by cell. See the
List ofid
attribute values for header cells. See the
Cell height. See the
Suppress word wrapping. See the
Number of rows spanned by cell. See the
Scope covered by header cells. See the
Vertical alignment of data in cell. See the
Cell width. See the
Create a grid of frames. See the
The number of columns of frames in the frameset. See the
The number of rows of frames in the frameset. See the
Create a frame. See the
Request frame borders. See the
URI designating a long description of this image or frame. See the
Frame margin height, in pixels. See the
Frame margin width, in pixels. See the
The frame name (object of thetarget
attribute). See the
When true, forbid user from resizing frame. See the
Specify whether or not the frame should have scrollbars. See the
A URI designating the initial frame contents. See the
Inline subwindows. See the
Aligns this object (vertically or horizontally) with respect to its surrounding text. See the
Request frame borders. See the
Frame height. See the
URI designating a long description of this image or frame. See the
Frame margin height, in pixels. See the
Frame margin width, in pixels. See the
The frame name (object of thetarget
attribute). See the
Specify whether or not the frame should have scrollbars. See the
A URI designating the initial frame contents. See the
Frame width. See the