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., Element.getAttribute(), but certain functions (e.g., Element.getAttributeNode()) or means of iterating give Attr types.
<div id="interfaceDiagram" style="display: inline-block; position: relative; width: 100%; padding-bottom: 11.666666666666666%; vertical-align: middle; overflow: hidden;"><svg style="display: inline-block; position: absolute; top: 0; left: 0;" viewbox="-50 0 600 70" preserveAspectRatio="xMinYMin meet"><a xlink:href="https://developer.mozilla.org/en-US/docs/Web/API/EventTarget" target="_top"><rect x="1" y="1" width="110" height="50" fill="#fff" stroke="#D4DDE4" stroke-width="2px" /><text x="56" y="30" font-size="12px" font-family="Consolas,Monaco,Andale Mono,monospace" fill="#4D4E53" text-anchor="middle" alignment-baseline="middle">EventTarget</text></a><polyline points="111,25 121,20 121,30 111,25" stroke="#D4DDE4" fill="none"/><line x1="121" y1="25" x2="151" y2="25" stroke="#D4DDE4"/><a xlink:href="https://developer.mozilla.org/en-US/docs/Web/API/Node" target="_top"><rect x="151" y="1" width="75" height="50" fill="#fff" stroke="#D4DDE4" stroke-width="2px" /><text x="188.5" y="30" font-size="12px" font-family="Consolas,Monaco,Andale Mono,monospace" fill="#4D4E53" text-anchor="middle" alignment-baseline="middle">Node</text></a><polyline points="226,25 236,20 236,30 226,25" stroke="#D4DDE4" fill="none"/><line x1="236" y1="25" x2="266" y2="25" stroke="#D4DDE4"/><a xlink:href="https://developer.mozilla.org/en-US/docs/Web/API/Attr" target="_top"><rect x="266" y="1" width="75" height="50" fill="#F4F7F8" stroke="#D4DDE4" stroke-width="2px" /><text x="303.5" y="30" font-size="12px" font-family="Consolas,Monaco,Andale Mono,monospace" fill="#4D4E53" text-anchor="middle" alignment-baseline="middle">Attr</text></a></svg></div>
a:hover text { fill: #0095DD; pointer-events: all;}
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 Node. You should not be using any Node properties or methods on Attr objects. Starting in Gecko 7.0 (Firefox 7.0 / Thunderbird 7.0 / SeaMonkey 2.4), the ones that are going to be removed output warning messages to the console. You should revise your code accordingly. See 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.
ownerElementDeprecated since Gecko 7.0 Obsolete since Gecko 29.0- This property has been removed from Firefox 29. Since you can only get Attr objects from elements, you should already know the owner.
- Contrary to above claim, Document.evaluate can return Attr objects from an XPath, in which case you would not easily know the owner.
schemaTypeInfo?specified- This property always returns
true. Originally, it returnedtrueif the attribute was explicitly specified in the source code or by a script, andfalseif 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
Attr.nameinstead. nodeType- This property now always returns 2 (
ATTRIBUTE_NODE). nodeValue- Use
Attr.valueinstead. 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
Attrobject from anElement, 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
Attr.valueinstead.
The following methods have been deprecated:
appendChild()- Modify the value of
Attr.valueinstead. 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
Element.setAttribute()instead. createAttributeNS()- Use
Element.setAttributeNS()instead. getAttributeNode()- Use
Element.getAttribute()instead. getAttributeNodeNS()- Use
Element.getAttributeNS()instead. hasAttributes()Obsolete since Gecko 21.0- This method now always returns false.
hasChildNodes()- This method now always returns false.
insertBefore()- Modify the value of
Attr.valueinstead. 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
Element.removeAttribute()instead. removeChild()- Modify the value of
Attr.valueinstead. replaceChild()- Modify the value of
Attr.valueinstead. setAttributeNode()- Use
Element.setAttribute()instead. setAttributeNodeNS()- Use
Element.setAttributeNS()instead.
Specifications
| Specification | Status | Comment |
|---|---|---|
| DOM4 The definition of 'Attr' in that specification. |
Working Draft | |
| Document Object Model (DOM) Level 3 Core Specification The definition of 'Attr' in that specification. |
Recommendation | Initial definition |
Browser compatibility
| Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari |
|---|---|---|---|---|---|
| Basic support | (Yes) [1] | (Yes) | (Yes) | (Yes) | (Yes) |
| Feature | Android | Android Webview | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile | Chrome for Android |
|---|---|---|---|---|---|---|---|
| Basic support | (Yes) | (Yes) [1] | (Yes) | (Yes) | (Yes) | (Yes) | (Yes) [1] |
[1] As of Chrome 45, this property no longer inherits from Node.
Document Tags and Contributors
Tags:
Contributors to this page:
srguiwizm,
AlfredoLlaquet,
jpmedley,
Sebastianz,
Delapouite,
fscholz,
teoli,
kohei.yoshino,
tregagnon,
blackoutjack,
alispivak,
Sheppy,
Ms2ger,
ethertank,
dbruant,
Brettz9
Last updated by:
srguiwizm,