Element.removeAttributeNode

  • Revision slug: Web/API/element.removeAttributeNode
  • Revision title: element.removeAttributeNode
  • Revision id: 477045
  • Created:
  • Creator: kscarfone
  • Is current revision? Yes
  • Comment Updated tags

Revision Content

{{ DomRef() }}

Summary

removeAttributeNode removes the specified attribute from the current element.

Syntax

removedAttr = element.removeAttributeNode(attributeNode)
  • attributeNode is the Attr node that needs to be removed.
  • removedAttr is the removed Attr node.

Example

// <div id="top" align="center" />
var d = document.getElementById("top"); 
var d_align = d.getAttributeNode("align"); 
d.removeAttributeNode(d_align); 
// align is now removed: <div id="top" />

Notes

If the removed Attribute has a default value it is immediately replaced. The replacing attribute has the same namespace URI and local name, as well as the original prefix, when applicable.

There is no removeAttributeNodeNS (unlike the pair setAttributeNode and setAttributeNodeNS which need to know which existing attribute to replace (if any), removeAttributeNode has no such requirement). removeAttributeNode can remove namespaced as well as non-namespaced attributes.

{{ DOMAttributeMethods() }}

Specification

DOM Level 2 Core: removeAttributeNode (introduced in DOM Level 1 Core)

{{ languages( { "fr": "fr/DOM/element.removeAttributeNode", "ja": "ja/DOM/element.removeAttributeNode", "pl": "pl/DOM/element.removeAttributeNode" } ) }}

Revision Source

<p>{{ DomRef() }}</p>
<h3 id="Summary" name="Summary">Summary</h3>
<p><code>removeAttributeNode</code> removes the specified attribute from the current element.</p>
<h3 id="Syntax" name="Syntax">Syntax</h3>
<pre class="eval">
<em>removedAttr</em> = <em>element</em>.removeAttributeNode(<em>attributeNode</em>)
</pre>
<ul>
  <li><code>attributeNode</code> is the <code>Attr</code> node that needs to be removed.</li>
  <li><code>removedAttr</code> is the removed <code>Attr</code> node.</li>
</ul>
<h3 id="Example" name="Example">Example</h3>
<pre>
// &lt;div id="top" align="center" /&gt;
var d = document.getElementById("top"); 
var d_align = d.getAttributeNode("align"); 
d.removeAttributeNode(d_align); 
// align is now removed: &lt;div id="top" /&gt;
</pre>
<h3 id="Notes" name="Notes">Notes</h3>
<p>If the removed Attribute has a default value it is immediately replaced. The replacing attribute has the same namespace URI and local name, as well as the original prefix, when applicable.</p>
<p>There is no <code>removeAttributeNodeNS</code> (unlike the pair <code>setAttributeNode </code>and<code> </code><code>setAttributeNodeNS</code> which need to know which existing attribute to replace (if any), <code>removeAttributeNode <span style="font-family: Verdana,Tahoma,sans-serif;">has no such requirement</span></code>). <code>removeAttributeNode </code>can remove namespaced as well as non-namespaced attributes.</p>
<p>{{ DOMAttributeMethods() }}</p>
<h3 id="Specification" name="Specification">Specification</h3>
<p><a class="external" href="http://www.w3.org/TR/DOM-Level-2-Core/core.html#ID-D589198">DOM Level 2 Core: removeAttributeNode</a> (introduced in <a class="external" href="http://www.w3.org/TR/REC-DOM-Level-1/level-one-core.html#method-removeAttributeNode">DOM Level 1 Core</a>)</p>
<p>{{ languages( { "fr": "fr/DOM/element.removeAttributeNode", "ja": "ja/DOM/element.removeAttributeNode", "pl": "pl/DOM/element.removeAttributeNode" } ) }}</p>
Revert to this revision