Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

Revision 1100431 of NamedNodeMap

  • Revision slug: Web/API/NamedNodeMap
  • Revision title: NamedNodeMap
  • Revision id: 1100431
  • Created:
  • Creator: bunnrf
  • Is current revision? Yes
  • Comment

Revision Content

{{APIRef("DOM")}}

The NamedNodeMap interface represents a collection of {{domxref("Attr")}} objects. Objects inside a NamedNodeMap are not in any particular order, unlike {{domxref("NodeList")}}, although they may be accessed by an index as in an array.

A NamedNodeMap object is live and will thus be auto-updated if changes are made to its contents internally or elsewhere.

Although called NamedNodeMap, this interface doesn't deal with {{domxref("Node")}} objects but with {{domxref("Attr")}} objects, which were originally a specialized class of {{domxref("Node")}}, and still are in some implementations.

Properties

This interface doesn't inherit any property.

{{domxref("NamedNodeMap.length")}} {{ReadOnlyInline}}
Returns the amount of objects in the map.

Methods

This interface doesn't inherit any method.

{{domxref("NamedNodeMap.getNamedItem()")}}
Returns a {{domxref("Attr")}}, corresponding to the given name.
{{domxref("NamedNodeMap.setNamedItem()")}}
Replaces, or adds, the {{domxref("Attr")}} identified in the map by the given name.
{{domxref("NamedNodeMap.removeNamedItem()")}}
Removes the {{domxref("Attr")}} identified by the given map.
{{domxref("NamedNodeMap.item()")}}
Returns the {{domxref("Attr")}} at the given index, or null if the index is higher or equal to the number of nodes.
{{domxref("NamedNodeMap.getNamedItemNS()")}}
Returns a {{domxref("Attr")}} identified by a namespace and related local name.
{{domxref("NamedNodeMap.setNamedItemNS()")}}
Replaces, or adds, the {{domxref("Attr")}} identified in the map by the given namespace and related local name.
{{domxref("NamedNodeMap.removeNamedItemNS()")}}
Removes the {{domxref("Attr")}} identified by the given namespace and related local name.

Specifications

Specification Status Comment
{{SpecName('DOM WHATWG', '#interface-namednodemap', 'NamedNodeMap')}} {{Spec2('DOM WHATWG')}} Deals with {{domxref("Attr")}} instead of {{domxref("Node")}}
{{SpecName('DOM3 Core', 'core.html#ID-1780488922', 'NamedNodeMap')}} {{Spec2('DOM3 Core')}} No change from {{SpecName('DOM2 Core')}}
{{SpecName('DOM2 Core', 'core.html#ID-1780488922', 'NamedNodeMap')}} {{Spec2('DOM2 Core')}} Added getNamedItemNS(), setNamedItemNS() and removeNamedItemNS()
{{SpecName('DOM1', 'core.html#ID-1780488922', 'NamedNodeMap')}} {{Spec2('DOM1')}} Initial definition

Browser compatibility

{{CompatibilityTable}}

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support {{CompatVersionUnknown}} {{CompatVersionUnknown}} {{CompatVersionUnknown}} {{CompatVersionUnknown}} {{CompatVersionUnknown}}
Deals with {{domxref("Attr")}} rather than {{domxref("Node")}} {{CompatUnknown}} {{CompatGeckoDesktop(22)}}[1] {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}}
Feature Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support {{CompatVersionUnknown}} {{CompatVersionUnknown}} {{CompatVersionUnknown}} {{CompatVersionUnknown}} {{CompatVersionUnknown}}
Deals with {{domxref("Attr")}} rather than {{domxref("Node")}} {{CompatUnknown}} {{CompatGeckoMobile(22)}}[1] {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}}

[1] In Gecko 22 this interface was named mozNamedAttrMap. In Gecko 34 it was named back to NamedNodeMap.

See also

  • {{domxref("Element.attributes")}}

Revision Source

<div>{{APIRef("DOM")}}</div>

<p>The <code><strong>NamedNodeMap</strong></code> interface represents a collection of {{domxref("Attr")}} objects. Objects inside a <code>NamedNodeMap</code> are not in any particular order, unlike {{domxref("NodeList")}}, although they may be accessed by an index as in an array.</p>

<p>A <code>NamedNodeMap</code> object is&nbsp;<em>live</em> and will thus be auto-updated if changes are made to its contents internally or elsewhere.</p>

<div class="note">
<p>Although called <code>NamedNodeMap</code>, this interface doesn't deal with {{domxref("Node")}} objects but with {{domxref("Attr")}} objects, which were originally a specialized class of {{domxref("Node")}}, and still are in some implementations.</p>
</div>

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

<p><em>This interface doesn't inherit any property.</em></p>

<dl>
 <dt>{{domxref("NamedNodeMap.length")}} {{ReadOnlyInline}}</dt>
 <dd>Returns the amount of objects in the map.</dd>
</dl>

<h2 id="Methods">Methods</h2>

<p><em>This interface doesn't inherit any method.</em></p>

<dl>
 <dt>{{domxref("NamedNodeMap.getNamedItem()")}}</dt>
 <dd>Returns a {{domxref("Attr")}}, corresponding to the given name.</dd>
 <dt>{{domxref("NamedNodeMap.setNamedItem()")}}</dt>
 <dd>Replaces, or adds, the {{domxref("Attr")}} identified in the map by the given name.</dd>
 <dt>{{domxref("NamedNodeMap.removeNamedItem()")}}</dt>
 <dd>Removes the {{domxref("Attr")}} identified by the given map.</dd>
 <dt>{{domxref("NamedNodeMap.item()")}}</dt>
 <dd>Returns the {{domxref("Attr")}} at the given index, or <code>null</code> if the index is higher or equal to the number of nodes.</dd>
 <dt>{{domxref("NamedNodeMap.getNamedItemNS()")}}</dt>
 <dd>Returns a {{domxref("Attr")}} identified by a namespace and related local name.</dd>
 <dt>{{domxref("NamedNodeMap.setNamedItemNS()")}}</dt>
 <dd>Replaces, or adds, the {{domxref("Attr")}} identified in the map by the given namespace and related local name.</dd>
 <dt>{{domxref("NamedNodeMap.removeNamedItemNS()")}}</dt>
 <dd>Removes the {{domxref("Attr")}} identified by the given namespace and related local name.</dd>
</dl>

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

<table class="standard-table">
 <tbody>
  <tr>
   <th scope="col">Specification</th>
   <th scope="col">Status</th>
   <th scope="col">Comment</th>
  </tr>
  <tr>
   <td>{{SpecName('DOM WHATWG', '#interface-namednodemap', 'NamedNodeMap')}}</td>
   <td>{{Spec2('DOM WHATWG')}}</td>
   <td>Deals with {{domxref("Attr")}} instead of {{domxref("Node")}}</td>
  </tr>
  <tr>
   <td>{{SpecName('DOM3 Core', 'core.html#ID-1780488922', 'NamedNodeMap')}}</td>
   <td>{{Spec2('DOM3 Core')}}</td>
   <td>No change from {{SpecName('DOM2 Core')}}</td>
  </tr>
  <tr>
   <td>{{SpecName('DOM2 Core', 'core.html#ID-1780488922', 'NamedNodeMap')}}</td>
   <td>{{Spec2('DOM2 Core')}}</td>
   <td>Added <code>getNamedItemNS()</code>, <code>setNamedItemNS()</code> and <code>removeNamedItemNS()</code></td>
  </tr>
  <tr>
   <td>{{SpecName('DOM1', 'core.html#ID-1780488922', 'NamedNodeMap')}}</td>
   <td>{{Spec2('DOM1')}}</td>
   <td>Initial definition</td>
  </tr>
 </tbody>
</table>

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

<p>{{CompatibilityTable}}</p>

<div id="compat-desktop">
<table class="compat-table">
 <tbody>
  <tr>
   <th>Feature</th>
   <th>Chrome</th>
   <th>Firefox (Gecko)</th>
   <th>Internet Explorer</th>
   <th>Opera</th>
   <th>Safari</th>
  </tr>
  <tr>
   <td>Basic support</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatVersionUnknown}}</td>
  </tr>
  <tr>
   <td>Deals with {{domxref("Attr")}} rather than {{domxref("Node")}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatGeckoDesktop(22)}}<sup>[1]</sup></td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
  </tr>
 </tbody>
</table>
</div>

<div id="compat-mobile">
<table class="compat-table">
 <tbody>
  <tr>
   <th>Feature</th>
   <th>Android</th>
   <th>Firefox Mobile (Gecko)</th>
   <th>IE Mobile</th>
   <th>Opera Mobile</th>
   <th>Safari Mobile</th>
  </tr>
  <tr>
   <td>Basic support</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatVersionUnknown}}</td>
  </tr>
  <tr>
   <td>Deals with {{domxref("Attr")}} rather than {{domxref("Node")}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatGeckoMobile(22)}}<sup>[1]</sup></td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
  </tr>
 </tbody>
</table>
</div>

<p>[1] In Gecko 22 this interface was named <code>mozNamedAttrMap</code>. In Gecko 34 it was named back to <code>NamedNodeMap</code>.</p>

<h2 id="See_also">See also</h2>

<ul>
 <li>{{domxref("Element.attributes")}}</li>
</ul>
Revert to this revision