From http://www.w3schools.com (Copyright Refsnes Data)

XML DOM - The Element Object

prev next

The Element object represents an element in an XML document.


The Element object

The Element object represents an element in an XML document. Elements may contain attributes, other elements, or text. If an element contains text, the text is represented in a text-node.

IMPORTANT! Text is always stored in text nodes. A common error in DOM processing is to navigate to an element node and expect it to contain the text. However, even the simplest element node has a text node under it. For example, in <year>2005</year>, there is an element node (year), and a text node under it, which contains the text (2005).

Because the Element object is also a Node, it inherits the Node object's properties and methods.

IE: Internet Explorer, F: Firefox, O: Opera, W3C: World Wide Web Consortium (Internet Standard)

Element Object Properties

Property Description IE F O W3C
attributes Returns a NamedNodeMap of attributes for the element 5 1 9 Yes
baseURI Returns the absolute base URI of the element No 1 No Yes
childNodes Returns a NodeList of child nodes for the element 5 1 9 Yes
firstChild Returns the first child of the element 5 1 9 Yes
lastChild Returns the last child of the element 5 1 9 Yes
localName Returns the local part of the name of the element No 1 9 Yes
namespaceURI Returns the namespace URI of the element No 1 9 Yes
nextSibling Returns the node immediately following the element 5 1 9 Yes
nodeName Returns the name of the node, depending on its type 5 1 9 Yes
nodeType Returns the type of the node 5 1 9 Yes
ownerDocument Returns the root element (document object) for an element 5 1 9 Yes
parentNode Returns the parent node of the element 5 1 9 Yes
prefix Sets or returns the namespace prefix of the element No 1 9 Yes
previousSibling Returns the node immediately before the element 5 1 9 Yes
schemaTypeInfo Returns the type information associated with the element     No Yes
tagName Returns the name of the element 5 1 9 Yes
textContent Sets or returns the text content of the element and its descendants No 1 No Yes
text Returns the text of the node and its descendants. IE-only property 5 No No No
xml Returns the XML of the node and its descendants. IE-only property 5 No No No

Element Object Methods

Method Description IE F O W3C
appendChild() Adds a new child node to the end of the list of children of the node 5 1 9 Yes
cloneNode() Clones a  node 5 1 9 Yes
compareDocumentPosition() Compares the document position of two nodes No 1 No Yes
getAttribute() Returns the value of an attribute 5 1 9 Yes
getAttributeNS() Returns the value of an attribute (with a namespace) No 1 9 Yes
getAttributeNode() Returns an attribute node as an Attribute object 5 1 9 Yes
getAttributeNodeNS() Returns an attribute node (with a namespace) as an Attribute object No   9 Yes
getElementsByTagName() Returns a NodeList of matching element nodes, and their  children 5 1 9 Yes
getElementsByTagNameNS() Returns a NodeList of matching element nodes (with a namespace), and their  children No 1 9 Yes
getFeature(feature,version) Returns a DOM object which implements the specialized APIs of the specified feature and version     No Yes
getUserData(key) Returns 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     No Yes
hasAttribute() Returns whether an element has any attributes matching a specified name 5 1 9 Yes
hasAttributeNS() Returns whether an element has any attributes matching a specified name and namespace No 1 9 Yes
hasAttributes() Returns whether the element has any attributes 5 1 9 Yes
hasChildNodes() Returns whether the element has any child nodes 5 1 9 Yes
insertBefore() Inserts a new child node before an existing child node 5 1 9 Yes
isDefaultNamespace(URI) Returns whether the specified namespaceURI is the default     No Yes
isEqualNode() Checks if two nodes are equal No No No Yes
isSameNode() Checks if two nodes are the same node No 1 No Yes
isSupported(feature,version) Returns whether a specified feature is supported on the element     9 Yes
lookupNamespaceURI() Returns the namespace URI matching a specified prefix No 1 No Yes
lookupPrefix() Returns the prefix matching a specified namespace URI No 1 No Yes
normalize() Puts all text nodes underneath this element (including attributes) 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 5 1 9 Yes
removeAttribute() Removes a specified attribute 5 1 9 Yes
removeAttributeNS() Removes a specified attribute (with a namespace) No 1 9 Yes
removeAttributeNode() Removes a specified attribute node 5 1 9 Yes
removeChild() Removes a child node 5 1 9 Yes
replaceChild() Replaces a child node 5 1 9 Yes
setUserData(key,data,handler) Associates an object to a key on the element     No Yes
setAttribute() Adds a new attribute 5 1 9 Yes
setAttributeNS() Adds a new attribute (with a namespace)   1 9 Yes
setAttributeNode() Adds a new attribute node 5 1 9 Yes
setAttributeNodeNS(attrnode) Adds a new attribute node (with a namespace)     9 Yes
setIdAttribute(name,isId) If the isId property of the Attribute object is true, this method declares the specified attribute to be a user-determined ID attribute     No Yes
setIdAttributeNS(uri,name,isId) If the isId property of the Attribute object is true, this method declares the specified attribute (with a namespace) to be a user-determined ID attribute     No Yes
setIdAttributeNode(idAttr,isId) If the isId property of the Attribute object is true, this method declares the specified attribute to be a user-determined ID attribute     No Yes


prev next

From http://www.w3schools.com (Copyright Refsnes Data)