Home to Document Object Model | Up to Core
Prev Node | Next CharacterData


Attr
Object (inherits from Node).

Attr has no methods of its own. See also Element, as attr represents an attribute of a markup element.

Note that the DOM does not place Attr nodes within the hierarchy. They are considered mere properties of the associated Element node - their parentNode, previousSibling and nextSibling are null. An Attr's only possible child node types are Text and EntityReference.

Some random XML markup:

<!DOCTYPE doc PUBLIC "-//funnytoes//DTD docdtd XML V1//EN" "/usr/dtd/doc/doc.dtd">
<doc type="doctype">
  <docbody docname="first doc" author="funnytoes"/>
  <docbody docname="second doc &quot;last&quot;"/>
</doc>

The DOM objects here are:

  • A Document node, with two (direct) children:
    1. A DocumentType node, named "doc"
    2. An Element node, tagName "doc", attributes containing:
      • An Attr node, named "type", specified true, having a single child:
        1. A Text node containing "doctype".
      • Other Attr nodes for attributes from the DTD with default values
      ...and two children:
      1. An Element node, tagName "docbody", attributes containing:
        • An Attr node, named "docname", specified true, having a single child:
          1. A Text node containing "first doc".
        • An Attr node, named "author", specified true, having a single child:
          1. A Text node containing "funnytoes".
        • Other Attr nodes for attributes from the DTD with default values
        ...and no child nodes.
      2. An Element node, tagName "docbody", attributes containing:
        • An Attr node, named "docname", specified true, having four children:
          1. A Text node containing "second doc ".
          2. An EntityReference node for the first "&quot;".
          3. A Text node containing "last".
          4. An EntityReference node for the second "&quot;".
        • Other Attr nodes for attributes from the DTD with default values
        ...and no child nodes.

name
Attribute (read only, string)

Contains the name of this attribute.

ownerElement
Attribute (read only, Element)

Introduced in DOM Level 2. The Element that has this attribute (or null if it's not been set on any element).

specified
Attribute (read only, boolean)

True if the user (i.e. the document content) created the Attr (whether or not it's set on any element). False if the implementation created it (i.e. because the DTD says this attribute exists with a particular value on the element on which it's set).

value
Attribute (string; can raise DOMException)

The "plain" textual value of all Text and EntityReference child nodes. Setting this removes any existing child nodes and replaces them with a single Text node containing the value.

Exception:

NO_MODIFICATION_ALLOWED_ERR
This node is read only.

Log in or registerto write something here or to contact authors.