Home to Document Object Model | Up to Core
Prev DocumentFragment | Next NodeList


Element
Object (inherits from Node).

Represents the part of a document contained between start and end tags or, for an empty element, the empty tag. An element node may have any number of the following child nodes, which represent the content of the document within the tags:

Elements may also have attributes.

tagName
Attribute (read only, String)

The tag name from the markup.

For example, this element of markup

<P align="center">This is centred</P>
has a tagName of "P".

hasAttribute
Method
ECMAScript binding: hasAttribute(name) (returns boolean; name is a String)

Introduced in DOM Level 2.

Indicates the presence of an attribute node on this element (or by default) with a nodeName matching the given name.

hasAttributeNS
Method
ECMAScript binding: hasAttributeNS(namespaceURI, localName) (returns boolean; namespaceURI and localName are Strings)

Introduced in DOM Level 2.

This is the equivalent call to hasAttribute for namespaced markup.

getAttribute
Method
ECMAScript binding: getAttribute(name) (returns String; name is a String)

Returns the value of an attribute node on this element with a nodeName matching the given name. If no such node exists on this element, an empty string is returned.

Calling getAttribute("align") on the element in the example under tagName would return "center".

getAttributeNS
Method
ECMAScript binding: getAttributeNS(namespaceURI, localName) (returns String; namespaceURI and localName are Strings)

Introduced in DOM Level 2.

This is the equivalent call to getAttribute for namespaced markup.

getAttributeNode
Method
ECMAScript binding: getAttributeNode(name) (returns an attribute; name is a String)

Introduced in DOM Level 2.

Returns the attribute node on this element with a nodeName matching the given name. If no such node exists on this element, null is returned.

Calling getAttributeNode("align") on the element in the example under tagName would return an attribute node with a nodeName of "align" and a value of "center".

getAttributeNodeNS
Method
ECMAScript binding: getAttributeNodeNS(namespaceURI, localName) (returns an attribute; namespaceURI and localName are Strings)

Introduced in DOM Level 2.

This is the equivalent call to getAttributeNode for namespaced markup.

setAttribute
Method
ECMAScript binding: setAttribute(name, value) (name and value are Strings; can raise DOMException)

Sets the value of an attribute node on this element with a nodeName matching the given name to the given value. If no such node exists on this element, one is created.

Note: value will not be parsed by the implementation (i.e. it will be treated as literal text and output escaped). More complex values should be created as attribute nodes and added using setAttributeNode.

The exceptions thrown are:

INVALID_CHARACTER_ERR
The name given is invalid.
NO_MODIFICATION_ALLOWED_ERR
The node is read only.

setAttributeNS
Method
ECMAScript binding: setAttributeNS(namespaceURI, qualifiedName, value) (namespaceURI, qualifiedName and value are Strings; can raise DOMException)

Introduced in DOM Level 2.

This is the equivalent call to setAttribute for namespaced markup.

The exceptions thrown are:

NAMESPACE_ERR
The namespaceURI given is invalid.
INVALID_CHARACTER_ERR
The qualifiedName given is invalid.
NO_MODIFICATION_ALLOWED_ERR
The node is read only.

setAttributeNode
Method
ECMAScript binding: setAttributeNode(newAttr) (returns an attribute; newAttr is an attribute; can raise DOMException)

If an attribute node exists on this element with the same nodeName, it will be replaced and the old attribute node returned. Otherwise a new attribute node is attached to this element and null is returned.

Note: Use setAttributeNodeNS if the nodeName is qualified.

The exceptions thrown are:

WRONG_DOCUMENT_ERR
newAttr does not belong in this document.
INVALID_CHARACTER_ERR
The name given is invalid.
NO_MODIFICATION_ALLOWED_ERR
The node is read only.

setAttributeNodeNS
Method
ECMAScript binding: setAttributeNodeNS(newAttr) (newAttr is an attribute; can raise DOMException)

Introduced in DOM Level 2.

This is the equivalent call to setAttributeNode for namespaced markup.

The exceptions thrown are:

WRONG_DOCUMENT_ERR
newAttr does not belong in this document.
NAMESPACE_ERR
The namespaceURI given is invalid.
INVALID_CHARACTER_ERR
The qualifiedName given is invalid.
NO_MODIFICATION_ALLOWED_ERR
The node is read only.

removeAttribute
Method
ECMAScript binding: removeAttribute(name) (name is a String; can raise DOMException)

Removes an attribute node from this element with a nodeName matching the given name. If there is a default for that attribute, a new attribute node appears.

The exception thrown is:

NO_MODIFICATION_ALLOWED_ERR
The node is read only.

removeAttributeNS
Method
ECMAScript binding: removeAttributeNS(namespaceURI, localName) (namespaceURI and localName are Strings; can raise DOMException)

Introduced in DOM Level 2.

This is the equivalent call to removeAttribute for namespaced markup.

The exception thrown is:

NO_MODIFICATION_ALLOWED_ERR
The node is read only.

removeAttributeNode
Method
ECMAScript binding: removeAttributeNode(oldAttr) (returns an attribute; oldAttr is an attribute; can raise DOMException)

Removes an attribute node from this element with the same nodeName as oldAttr, returning the old attribute node. If there is a default for that attribute, a new attribute node appears.

The exception thrown is:

NO_MODIFICATION_ALLOWED_ERR
The node is read only.
NOT_FOUND_ERR
oldAttr cannot be found.

getElementsByTagName
Method
ECMAScript binding: getElementsByTagName(name) (returns a NodeList; name is a String)

Returns a list of all Element nodes with this node as their parent and a tagName matching name. A name of * matches all tagNames.

For example, calling getElementsByTagName("B") for this element of markup

<P>This is <B>bold</B></P>
would return a list containing one element.

getElementsByTagNameNS
Method
ECMAScript binding: getElementsByTagNameNS(namespaceURI, localName) (returns a NodeList; namespaceURI and localName are Strings)

Introduced in DOM Level 2.

This is the equivalent call to getElementsByTagName for namespaced markup. Both namespaceURI and localName take * to match any value.