Attr

  • Revision slug: DOM/Attr
  • Revision title: Attr
  • Revision id: 70471
  • Created:
  • Creator: dbruant
  • Is current revision? No
  • Comment /*Properties*/ Added what looked like a missing word for "ownerElement" description; Described the "specified" property's original specification, according to Rhinobook 4th Edtion; 41 words added, 1 words removed

Revision Content

This type represents a DOM element's attribute as an object. In most DOM methods, you will probably directly retrieve the attribute as a string (e.g., {{ domxref("Element.getAttribute()") }}, but certain functions (e.g., {{ domxref("Element.getAttributeNode()") }}) or means of iterating give Attr types.

Warning: In DOM Core 1, 2 and 3, Attr inherited from Node. This is no longer the case in DOM4. In order to bring the implementation of Attr up to specification, work is underway to change it to no longer inherit from {{ domxref("Node") }}. You should not be using any {{ domxref("Node") }} properties or methods on Attr objects. Starting in Gecko 7.0 {{ geckoRelease("7.0") }}, the ones that are going to be removed output warning messages to the console. You should revise your code accordingly. See {{ anch("Deprecated properties and methods") }} for a complete list.

Properties

isId
Indicates whether the attribute is an "ID attribute". An "ID attribute" being an attribute which value is expected to be unique across a DOM Document. In HTML DOM, "id" is the only ID attribute, but XML documents could define others. Whether or not an attribute is unique is often determined by a DTD or other schema description.
name
The attribute's name.
ownerElement {{ deprecated_inline("7.0") }}
This property has been deprecated and will be removed in the future. Since you can only get Attr objects from elements, you should already know the owner.
schemaTypeInfo
?
specified {{ deprecated_inline("7.0") }}
This property has been deprecated and will be removed in the future; it now always returns true. Originally, it returned true if the attribute was explicitly specified in the source code or by a script, and false if its value came from the default one defined in the document's DTD.
value
The attribute's value.

Deprecated properties and methods

The following properties have been deprecated. Where available, the appropriate replacement is provided.

attributes
This property now always returns NULL.
childNodes
This property now always returns NULL.
firstChild
This property now always returns NULL.
lastChild
This property now always returns NULL.
nextSibling
This property now always returns NULL.
nodeName
Use {{ domxref("Attr.name") }} instead.
nodeType
This property now always returns 2 (ATTRIBUTE_NODE).
nodeValue
Use {{ domxref("Attr.value") }} instead.
ownerDocument
You shouldn't have been using this in the first place, so you probably don't care that this is going away.
ownerElement
Since you get an Attr object from an {{ domxref("Element") }}, you should already know the associated element.
parentNode
This property now always returns NULL.
previousSibling
This property now always returns NULL.
specified
This property now always returns true.
textContent
Use {{ domxref("Attr.value") }} instead.

The following methods have been deprecated:

appendChild()
Modify the value of {{ domxref("Attr.value") }} instead.
cloneNode()
You shouldn't have been using this in the first place, so you probably don't care that this is going away.
createAttribute()
Use {{ domxref("Attr.setAttribute()") }} instead.
createAttributeNS()
Use {{ domxref("Attr.setAttributeNS()") }} instead.
getAttributeNode()
Use {{ domxref("Attr.getAttribute()") }} instead.
getAttributeNodeNS()
Use {{ domxref("Attr.getAttributeNS()") }} instead.
hasAttributes()
This method now always returns false.
hasChildNodes()
This method now always returns false.
insertBefore()
Modify the value of {{ domxref("Attr.value") }} instead.
isSupported()
You shouldn't have been using this in the first place, so you probably don't care that this is going away.
isEqualNode()
You shouldn't have been using this in the first place, so you probably don't care that this is going away.
normalize()
You shouldn't have been using this in the first place, so you probably don't care that this is going away.
removeAttributeNode()
Use {{ domxref("Attr.removeAttribute()") }} instead.
removeChild()
Modify the value of {{domxref("Attr.value)")) instead.
replaceChild()
Modify the value of {{ domxref("Attr.value") }} instead.
setAttributeNode()
Use {{ domxref("Attr.setAttribute()") }} instead.
setAttributeNodeNS()
Use {{ domxref("Attr.setAttributeNS()") }} instead.

Specifications

Revision Source

<p>This type represents a DOM element's attribute as an object. In most DOM methods, you will probably directly retrieve the attribute as a string (e.g., {{ domxref("Element.getAttribute()") }}, but certain functions (e.g., {{ domxref("Element.getAttributeNode()") }}) or means of iterating give <code>Attr</code> types.</p>
<div class="warning"><strong>Warning:</strong> In DOM Core 1, 2 and 3, Attr inherited from Node. This is no longer the case in <a class="external" href="http://www.w3.org/TR/dom/">DOM4</a>. In order to bring the implementation of <code>Attr</code> up to specification, work is underway to change it to no longer inherit from {{ domxref("Node") }}. You should not be using any {{ domxref("Node") }} properties or methods on <code>Attr</code> objects. Starting in Gecko 7.0 {{ geckoRelease("7.0") }}, the ones that are going to be removed output warning messages to the console. You should revise your code accordingly. See {{ anch("Deprecated properties and methods") }} for a complete list.</div>
<h2 id="Properties">Properties</h2>
<dl> <dt><code><a class="internal" href="/En/DOM/Attr.isId" title="En/DOM/Attr.isId">isId</a></code></dt> <dd>Indicates whether the attribute is an "ID attribute". An "ID attribute" being an attribute which value is expected to be unique across a DOM Document. In HTML DOM, "id" is the only ID attribute, but XML documents could define others. Whether or not an attribute is unique is often determined by a DTD or other schema description.</dd> <dt><code><a class="internal" href="/En/DOM/Attr.name" title="En/DOM/Attr.name">name</a></code></dt> <dd>The attribute's name.</dd> <dt><code><a class="internal" href="/En/DOM/Attr.ownerElement" title="En/DOM/Attr.ownerElement">ownerElement</a></code> {{ deprecated_inline("7.0") }}</dt> <dd>This property has been deprecated and will be removed in the future. Since you can only get Attr objects from elements, you should already know the owner.</dd> <dt><code><a class="internal" href="/En/DOM/Attr.schemaTypeInfo" title="En/DOM/Attr.schemaTypeInfo">schemaTypeInfo</a></code></dt> <dd><code>?</code></dd> <dt><code><a class="internal" href="/En/DOM/Attr.specified" title="En/DOM/Attr.specified">specified </a></code>{{ deprecated_inline("7.0") }}</dt> <dd>This property has been deprecated and will be removed in the future; it now always returns <code>true</code>. Originally, it returned <code>true </code>if the attribute was explicitly specified in the source code or by a script, and <code>false</code> if its value came from the default one defined in the document's <acronym title="Document Type Definition">DTD</acronym>.</dd> <dt><code><a class="internal" href="/En/DOM/Attr.value" title="En/DOM/Attr.value">value</a></code></dt> <dd>The attribute's value.</dd>
</dl><h2 id="Deprecated_properties_and_methods">Deprecated properties and methods</h2>
<p>The following properties have been deprecated. Where available, the appropriate replacement is provided.</p>
<dl> <dt><code>attributes</code></dt> <dd>This property now always returns <code>NULL</code>.</dd> <dt><code>childNodes</code></dt> <dd>This property now always returns <code>NULL</code>.</dd> <dt><code>firstChild</code></dt> <dd>This property now always returns <code>NULL</code>.</dd> <dt><code>lastChild</code></dt> <dd>This property now always returns <code>NULL</code>.</dd> <dt><code>nextSibling</code></dt> <dd>This property now always returns <code>NULL</code>.</dd> <dt><code>nodeName</code></dt> <dd>Use {{ domxref("Attr.name") }} instead.</dd> <dt><code>nodeType</code></dt> <dd>This property now always returns 2 (<code>ATTRIBUTE_NODE</code>).</dd> <dt><code>nodeValue</code></dt> <dd>Use {{ domxref("Attr.value") }} instead.</dd> <dt><code>ownerDocument</code></dt> <dd>You shouldn't have been using this in the first place, so you probably don't care that this is going away.</dd> <dt><code>ownerElement</code></dt> <dd>Since you get an <code>Attr</code> object from an {{ domxref("Element") }}, you should already know the associated element.</dd> <dt><code>parentNode</code></dt> <dd>This property now always returns <code>NULL</code>.</dd> <dt><code>previousSibling</code></dt> <dd>This property now always returns <code>NULL</code>.</dd> <dt><code>specified</code></dt> <dd>This property now always returns <code>true</code>.</dd> <dt><code>textContent</code></dt> <dd>Use {{ domxref("Attr.value") }} instead.</dd> <br>
</dl>
<p>The following methods have been deprecated:</p>
<dl> <dt><code>appendChild()</code></dt> <dd>Modify the value of {{ domxref("Attr.value") }} instead.</dd> <dt><code>cloneNode()</code></dt> <dd>You shouldn't have been using this in the first place, so you probably don't care that this is going away.</dd> <dt><code>createAttribute()</code></dt> <dd>Use {{ domxref("Attr.setAttribute()") }} instead.</dd> <dt><code>createAttributeNS()</code></dt> <dd>Use {{ domxref("Attr.setAttributeNS()") }} instead.</dd> <dt><code>getAttributeNode()</code></dt> <dd>Use {{ domxref("Attr.getAttribute()") }} instead.</dd> <dt><code>getAttributeNodeNS()</code></dt> <dd>Use {{ domxref("Attr.getAttributeNS()") }} instead.</dd> <dt><code>hasAttributes()</code></dt> <dd>This method now always returns false.</dd> <dt><code>hasChildNodes()</code></dt> <dd>This method now always returns false.</dd> <dt><code>insertBefore()</code></dt> <dd>Modify the value of {{ domxref("Attr.value") }} instead.</dd> <dt><code>isSupported()</code></dt> <dd>You shouldn't have been using this in the first place, so you probably don't care that this is going away.</dd> <dt><code>isEqualNode()</code></dt> <dd>You shouldn't have been using this in the first place, so you probably don't care that this is going away.</dd> <dt><code>normalize()</code></dt> <dd>You shouldn't have been using this in the first place, so you probably don't care that this is going away.</dd> <dt><code>removeAttributeNode()</code></dt> <dd>Use {{ domxref("Attr.removeAttribute()") }} instead.</dd> <dt><code>removeChild()</code></dt> <dd>Modify the value of {{domxref("Attr.value)")) instead.</dd> <dt><code>replaceChild()</code></dt> <dd>Modify the value of {{ domxref("Attr.value") }} instead.</dd> <dt><code>setAttributeNode()</code></dt> <dd>Use {{ domxref("Attr.setAttribute()") }} instead.</dd> <dt><code>setAttributeNodeNS()</code></dt> <dd>Use {{ domxref("Attr.setAttributeNS()") }} instead.</dd>
</dl>
<h2 id="Specifications">Specifications</h2>
<ul> <li><a class="external" href="http://www.w3.org/TR/DOM-Level-3-Core/core.html#ID-637646024" title="http://www.w3.org/TR/DOM-Level-3-Core/core.html#ID-637646024">Document Object Model Core level 3: Interface Attr</a></li> <li><a class="external" href="http://www.w3.org/TR/dom/#interface-attr">Document Object Model 4: Interface Attr</a></li>
</ul>
Revert to this revision