Element

Elements are the main building block of an XML document. They have a name, an associated namespace, attributes, text, and child elements.

Members

Functions

getAttribute
DOMString getAttribute(DOMString name)

Retrieves an attribute value by name.

getAttributeNS
DOMString getAttributeNS(DOMString namespaceURI, DOMString localName)

Retrieves an attribute value by local name and namespace URI. Per the XML Namespaces specification, applications must use the value null as the namespaceURI parameter for methods if they wish to have no namespace.

getAttributeNode
Attr getAttributeNode(DOMString name)

Retrieves an attribute node by name.

getAttributeNodeNS
Attr getAttributeNodeNS(DOMString namespaceURI, DOMString localName)

Retrieves an Attr node by local name and namespace URI. Per the XML Namespaces specification, applications must use the value null as the namespaceURI parameter for methods if they wish to have no namespace.

getElementsByTagName
NodeList getElementsByTagName(DOMString name)

Returns a NodeList of all descendant Elements with a given tag name, in document order.

getElementsByTagNameNS
NodeList getElementsByTagNameNS(DOMString namespaceURI, DOMString localName)

Returns a NodeList of all the descendant Elements with a given local name and namespace URI in document order.

hasAttribute
bool hasAttribute(DOMString name)

Returns true when an attribute with a given name is specified on this element or has a default value, false otherwise.

hasAttributeNS
bool hasAttributeNS(DOMString namespaceURI, DOMString localName)

Returns true when an attribute with a given localName and namespaceURI is specified on this element or has a default value, false otherwise. Per the XML Namespaces specification, applications must use the value null as the namespaceURI parameter for methods if they wish to have no namespace.

removeAttribute
void removeAttribute(DOMString name)

Removes an attribute by name. If a default value for the removed attribute is defined in the DTD, a new attribute immediately appears with the default value as well as the corresponding namespace URI, local name, and prefix when applicable. To remove an attribute by local name and namespace URI, use the removeAttributeNS method.

removeAttributeNS
void removeAttributeNS(DOMString namespaceURI, DOMString localName)

Removes an attribute by local name and namespace URI. If a default value for the removed attribute is defined in the DTD, a new attribute immediately appears with the default value as well as the corresponding namespace URI, local name, and prefix when applicable. Per the XML Namespaces specification, applications must use the value null as the namespaceURI parameter for methods if they wish to have no namespace.

removeAttributeNode
Attr removeAttributeNode(Attr oldAttr)

Removes the specified attribute node. If a default value for the removed attribute is defined in the DTD, a new attribute immediately appears with the default value as well as the corresponding namespace URI, local name, and prefix when applicable.

setAttribute
void setAttribute(DOMString name, DOMString 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 an Attr node plus any Text and EntityReference nodes, build the appropriate subtree, and use setAttributeNode to assign it as the value of an attribute. To set an attribute with a qualified name and namespace URI, use the setAttributeNS method.

setAttributeNS
void setAttributeNS(DOMString namespaceURI, DOMString qualifiedName, DOMString value)

Adds a new attribute. If an attribute with the same local name and namespace URI is already present on the element, its prefix is changed to be the prefix part of the qualifiedName, and its value is changed to be 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 an Attr node plus any Text and EntityReference nodes, build the appropriate subtree, and use setAttributeNode to assign it as the value of an attribute. Per the XML Namespaces specification, applications must use the value null as the namespaceURI parameter for methods if they wish to have no namespace.

setAttributeNode
Attr setAttributeNode(Attr newAttr)

Adds a new attribute node. If an attribute with that name (nodeName) is already present in the element, it is replaced by the new one. Replacing an attribute node by itself has no effect. To add a new attribute node with a qualified name and namespace URI, use the setAttributeNodeNS method.

setAttributeNodeNS
Attr setAttributeNodeNS(Attr newAttr)

Adds a new attribute. If an attribute with that local name and that namespace URI is already present in the element, it is replaced by the new one. Replacing an attribute node by itself has no effect. Per the XML Namespaces specification, applications must use the value null as the namespaceURI parameter for methods if they wish to have no namespace.

setIdAttribute
void setIdAttribute(DOMString name, bool isId)
setIdAttributeNS
void setIdAttributeNS(DOMString namespaceURI, DOMString localName, bool isId)
setIdAttributeNode
void setIdAttributeNode(Attr idAttr, bool isId)

If the parameter isId is true, this method declares the specified attribute to be a user-determined ID attribute. This affects the value of Attr.isId and the behavior of Document.getElementById, but does not change any schema that may be in use, in particular this does not affect the Attr.schemaTypeInfo of the specified Attr node. Use the value false for the parameter isId to undeclare an attribute for being a user-determined ID attribute.

Properties

schemaTypeInfo
XMLTypeInfo schemaTypeInfo [@property getter]

The type information associated with this element.

tagName
DOMString tagName [@property getter]

The name of the element. If Node.localName is different from null, this attribute is a qualified name.

Inherited Members

From Node

nodeType
NodeType nodeType [@property getter]

A code representing the type of the underlying object.

nodeName
DOMString nodeName [@property getter]

The name of this node, depending on its type.

localName
DOMString localName [@property getter]

Returns the local part of the qualified name of this node.

prefix
DOMString prefix [@property getter]
DOMString prefix [@property setter]

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.

namespaceURI
DOMString namespaceURI [@property getter]

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.

baseURI
DOMString baseURI [@property getter]

The absolute base URI of this node or null if the implementation wasn't able to obtain an absolute URI

nodeValue
DOMString nodeValue [@property getter]
DOMString nodeValue [@property setter]

The value of this node, depending on its type.

textContent
DOMString textContent [@property getter]

Returns the text content, if there's any.

textContent
DOMString textContent [@property setter]

Sets the text content, it there's any.

parentNode
Node parentNode [@property getter]

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.

childNodes
NodeList childNodes [@property getter]

A NodeList that contains all children of this node. If there are no children, this is a NodeList containing no nodes.

firstChild
Node firstChild [@property getter]

The first child of this node. If there is no such node, this returns null.

lastChild
Node lastChild [@property getter]

The last child of this node. If there is no such node, this returns null.

previousSibling
Node previousSibling [@property getter]

The node immediately preceding this node. If there is no such node, this returns null.

nextSibling
Node nextSibling [@property getter]

The node immediately following this node. If there is no such node, this returns null.

ownerDocument
Document ownerDocument [@property getter]

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.

attributes
NamedNodeMap attributes [@property getter]

A NamedNodeMap containing the attributes of this node (if it is an Element) or null otherwise.

hasAttributes
bool hasAttributes()

Returns whether this node (if it is an element) has any attributes.

insertBefore
Node insertBefore(Node newChild, Node refChild)

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.

replaceChild
Node replaceChild(Node newChild, Node oldChild)

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.

removeChild
Node removeChild(Node oldChild)

Removes the child node indicated by oldChild from the list of children, and returns it.

appendChild
Node appendChild(Node newChild)
Undocumented in source.
hasChildNodes
bool hasChildNodes()

Returns whether this node has any children.

cloneNode
Node cloneNode(bool deep)

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.

isSameNode
bool isSameNode(Node other)
Undocumented in source.
isEqualNode
bool isEqualNode(Node arg)
Undocumented in source.
normalize
void 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.

isSupported
bool isSupported(string feature, string version_)

Tests whether the DOM implementation implements a specific feature and that feature is supported by this node.

getFeature
Object getFeature(string feature, string version_)
Undocumented in source.
getUserData
UserData getUserData(string key)

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.

setUserData
UserData setUserData(string key, UserData data, UserDataHandler handler)

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.

compareDocumentPosition
BitFlags!DocumentPosition compareDocumentPosition(Node other)

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.

lookupPrefix
DOMString lookupPrefix(DOMString namespaceURI)

Look up the prefix associated to the given namespace URI, starting from this node. The default namespace declarations are ignored by this method.

lookupNamespaceURI
DOMString lookupNamespaceURI(DOMString prefix)

Look up the namespace URI associated to the given prefix, starting from this node.

isDefaultNamespace
bool isDefaultNamespace(DOMString namespaceURI)

This method checks if the specified namespaceURI is the default namespace or not.

Meta