Element Interface
The Element is the most common of all interfaces. The boudaries of an Element are dilimited by a set of start end tags. Each element has a type, identified by name and may have a set of attributes.
IDL Definition
Interface Element:Node {
readonly attribute DOMString tagName;
DOMString getAttribute(in DomString name);
void setAttribute(in DOMString name,
in DOMString value)
raises(DOMException);
void removeAttribute(in DOMString name)
raises(DOMException);
Attr getAttributeNode(in DOMString name);
Attr setAttributeNode(in Attr newAttr)
raises(DOMException);
Attr removeAttributeNode(in Attr oldAttr)
raises(DOMException);
NodeList getElementsByTagName(in DOMString name);
void normalize();
};
Semantic Requirements
- <Element> nodes may have attributes associated with them.
- The generic attribute "attributes" (from the Node interface) may be used to retrieve the set of all attributes for an element.
Attributes
- The tagName attribute contains the name of the element.
Methods
- The getAttribute(name) method retrieves an attribute value by name.
- The getAttribute(name) method returns the Attr value as a string. If the attribute has no default or specified value, it will return the empty string.
- The setAttribute(name,value) method adds a new attribute.
- If an attribute is already present in the element with that name, then its
value is changed to be the one of the value parameter.
- The removeAttribute(name) method removes an attribute by name.
If the removed attribute has a default value, it is immediately replaced.
- The getAttributeNode(name) method retrieves an <Attr> node
by name.
- The getAttributeNode(name) method returns the <Attr> node
with the specified attribute or null if there is no such attribute.
- The setAttributeNode(newAttr) method adds a new attribute node.
- If the new attribute node to be added by the setAttributeNode(newAttr) method is already present in the element, then it is replaced by the new one.
- If the new <Attr> replaces an existing attribute node with the same
name, then the setAttributeNode(newAttr) method returns the previously
existing <Attr> node, otherwise it returns null.
- The removeAttributeNode(oldAttr) method removes the specified
attribute node.
- If the removed <Attr> is known to have a default value, an attribute immediately appears containing the default value.
- The removeAtributeNode(oldAttr) method returns the node that was removed.
- The getElementsByTagName(name) method returns a NodeList of all descendant elements with a given tag name.
- The list of children returned by the getElementsByTagName(name) method is in the order the children were encountered in a preorder traversal of the Element tree.
- The getElementsByTagName(name) may use the special value of "*"
instead of a name to match all the tags in the Element tree.
- The normalize() method puts all the Text nodes in the full depth of the sub-tree underneath this Element into a "normal" form.
DOMExceptions
- The setAttribute(name, value) method raises an INVALID_CHARACTER_ERR DOMException if the specified name contains an invalid character.
- The setAttribute(name, value) method raises a NO_MODIFICATION_ALLOWED_ERR DOMException if this node is readonly.
- The removeAttribute(name) method raises a NO_MODIFICATION_ALLOWED_ERR DOMException if this node is readonly.
- The setAttributeNode(newAttr) method raises a NO_MODIFICATION_ALLOWED_ERR DOMException if this node is readonly.
- The removeAttributeNode(name) method raises a NO_MODIFICATION_ALLOWED_ERR DOMException if this node is readonly.
- The setAttributeNode(newAttr) method raises a WRONG_DOCUMENT_ERR DOMException if the new <Attr> was created from a different document than the one that created this element.
- The setAttributeNode(newAttr) method raises an INUSE_ATTRIBUTE_ERR DOMException if the new <Attr> is already an attribute of another Element object.
- The removeAttributeNode(oldAttr) method raises a NOT_FOUND_ERR DOMException if the old <Attr> is not an attribute of the element.
If you have comments or suggestions, email me at mbrady@nist.gov