aboutsummaryrefslogtreecommitdiff
path: root/files/ar/web/api/attr/index.html
blob: 0b01877112a8adc60c871162eb572505bb5a8f9a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
---
title: Attr
slug: Web/API/Attr
translation_of: Web/API/Attr
---
<h4 id="APIRefDOM">{{APIRef("DOM")}}</h4>

<p>The <code><strong>Attr</strong></code> interface represents one of a DOM element's attributes as an object. In most DOM methods, you will directly retrieve the attribute as a string (e.g., {{domxref("Element.getAttribute()")}}), but certain functions (e.g., {{domxref("Element.getAttributeNode()")}}) or means of iterating return <code>Attr</code> types.</p>

<p>{{InheritanceDiagram}}</p>

<div class="warning"><strong>Warning: </strong>Starting in Gecko 7.0 {{geckoRelease("7.0")}}, a number of deprecated properties and methods output warning messages to the console. You should revise your code accordingly. See <a href="#Deprecated_properties_and_methods">Deprecated properties and methods</a> for a complete list.</div>

<h2 id="Properties">Properties</h2>

<dl>
 <dt>{{domxref("Attr.name", "name")}} {{readOnlyInline}}</dt>
 <dd>The attribute's name.</dd>
 <dt>{{domxref("Attr.namespaceURI", "namespaceURI")}} {{readOnlyInline}}</dt>
 <dd>A {{domxref("DOMString")}} representing the namespace URI of the attribute, or <code>null</code> if there is no namespace.</dd>
 <dt>{{domxref("Attr.localName", "localName")}} {{readOnlyInline}}</dt>
 <dd>A {{domxref("DOMString")}} representing the local part of the qualified name of the attribute.</dd>
 <dt>{{domxref("Attr.prefix", "prefix")}} {{readOnlyInline}}</dt>
 <dd>A {{domxref("DOMString")}} representing the namespace prefix of the attribute, or <code>null</code> if no prefix is specified.</dd>
 <dt>{{domxref("Attr.ownerElement", "ownerElement")}} {{readOnlyInline}}</dt>
 <dd>
 <p>The element holding the attribute.</p>

 <div class="note">
 <p><strong>Note:</strong> DOM Level 4 removed this property. The assumption was that since you get an <code>Attr</code> object from an {{domxref("Element")}}, you should already know the associated element.<br>
  As that doesn't hold true in cases like <code>Attr</code> objects being returned by {{domxref("Document.evaluate")}}, the DOM Living Standard reintroduced the property.</p>

 <p>Gecko outputs a deprecation note starting from Gecko 7.0 {{geckoRelease("7.0")}}. This note was removed again in Gecko 49.0 {{geckoRelease("49.0")}}.</p>
 </div>
 </dd>
 <dt>{{domxref("Attr.specified", "specified")}} {{readOnlyInline}}</dt>
 <dd>This property 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>{{domxref("Attr.value", "value")}}</dt>
 <dd>The attribute's value.</dd>
</dl>

<div class="note">
<p><strong>Note:</strong> DOM Level 3 defined <code>namespaceURI</code>, <code>localName</code> and <code>prefix</code> on the {{domxref("Node")}} interface. In DOM4 they were moved to <code>Attr</code>.</p>

<p>This change is implemented in Chrome since version 46.0 and Firefox since version 48.0.</p>
</div>

<h2 id="Deprecated_properties_and_methods">Deprecated properties and methods</h2>

<p>The following properties have been deprecated. Where available, the appropriate replacement is noted.</p>

<dl>
 <dt><code>attributes</code></dt>
 <dd>This property now always returns <code>NULL</code>.</dd>
 <dt><code>childNodes</code> {{obsolete_inline(14)}}</dt>
 <dd>This property now always returns an empty {{domxref("NodeList")}}.</dd>
 <dt><code>firstChild</code> {{obsolete_inline(14)}}</dt>
 <dd>This property now always returns <code>NULL</code>.</dd>
 <dt><code>isId</code> {{readOnlyInline}}</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 {{Glossary("DTD")}} or other schema description.</dd>
 <dt><code>lastChild</code> {{obsolete_inline(14)}}</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>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>schemaTypeInfo</code> {{obsolete_inline}} {{readOnlyInline}}</dt>
 <dd>The type information associated with this attribute. While the type information contained in this attribute is guaranteed to be correct after loading the document or invoking {{domxref("Document.normalizeDocument")}}, this property may not be reliable if the node was moved.</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>
</dl>

<p>The following methods have been deprecated:</p>

<dl>
 <dt><code>appendChild()</code> {{obsolete_inline(14)}}</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("Element.setAttribute()")}} instead.</dd>
 <dt><code>createAttributeNS()</code></dt>
 <dd>Use {{domxref("Element.setAttributeNS()")}} instead.</dd>
 <dt><code>getAttributeNode()</code></dt>
 <dd>Use {{domxref("Element.getAttribute()")}} instead.</dd>
 <dt><code>getAttributeNodeNS()</code></dt>
 <dd>Use {{domxref("Element.getAttributeNS()")}} instead.</dd>
 <dt><code>hasAttributes()</code> {{obsolete_inline("21.0")}}</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("Element.removeAttribute()")}} instead.</dd>
 <dt><code>removeChild()</code> {{obsolete_inline(14)}}</dt>
 <dd>Modify the value of {{domxref("Attr.value")}} instead.</dd>
 <dt><code>replaceChild()</code> {{obsolete_inline(14)}}</dt>
 <dd>Modify the value of {{domxref("Attr.value")}} instead.</dd>
 <dt><code>setAttributeNode()</code></dt>
 <dd>Use {{domxref("Element.setAttribute()")}} instead.</dd>
 <dt><code>setAttributeNodeNS()</code></dt>
 <dd>Use {{domxref("Element.setAttributeNS()")}} instead.</dd>
</dl>

<h2 id="Specifications">Specifications</h2>

<table class="standard-table">
 <thead>
  <tr>
   <th scope="col">Specification</th>
   <th scope="col">Status</th>
   <th scope="col">Comment</th>
  </tr>
 </thead>
 <tbody>
  <tr>
   <td>{{SpecName("DOM WHATWG", "#interface-attr", "Attr")}}</td>
   <td>{{Spec2("DOM WHATWG")}}</td>
   <td>Added <code>ownerElement</code> property back</td>
  </tr>
  <tr>
   <td>{{SpecName("DOM4", "#interface-attr", "Attr")}}</td>
   <td>{{Spec2("DOM4")}}</td>
   <td>Moved <code>namespaceURI</code>, <code>prefix</code> and <code>localName</code> from {{domxref("Node")}} to this API and removed <code>ownerElement</code>, <code>schemaTypeInfo</code> and <code>isId</code>.</td>
  </tr>
  <tr>
   <td>{{SpecName("DOM3 Core", "core.html#ID-637646024", "Attr")}}</td>
   <td>{{Spec2("DOM3 Core")}}</td>
   <td>Initial definition</td>
  </tr>
 </tbody>
</table>

<h2 id="Browser_compatibility">Browser compatibility</h2>



<p>{{Compat("api.Attr")}}</p>