Element.removeAttribute

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

Revision Content

{{ DomRef() }}

Summary

removeAttribute removes an attribute from the specified element.

Syntax

element.removeAttribute(attrName); 
  • attrName is a string that names the attribute to be removed from element.

Example

// <div id="div1" align="left" width="200px"> 
document.getElementById("div1").removeAttribute("align"); 
// now: <div id="div1" width="200px">

Notes

You should use removeAttribute instead of setting the attribute value to null using setAttribute.

Attempting to remove an attribute that is not on the element doesn't raise an exception.

{{ DOMAttributeMethods() }}

Specification

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

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

Revision Source

<p>{{ DomRef() }}</p>
<h3 id="Summary" name="Summary">Summary</h3>
<p><code>removeAttribute</code> removes an attribute from the specified element.</p>
<h3 id="Syntax" name="Syntax">Syntax</h3>
<pre class="eval">
<em>element</em>.removeAttribute(<em>attrName</em>); 
</pre>
<ul>
  <li><code>attrName</code> is a string that names the attribute to be removed from <em>element</em>.</li>
</ul>
<h3 id="Example" name="Example">Example</h3>
<pre>
// &lt;div id="div1" align="left" width="200px"&gt; 
document.getElementById("div1").removeAttribute("align"); 
// now: &lt;div id="div1" width="200px"&gt;
</pre>
<h3 id="Notes" name="Notes">Notes</h3>
<p>You should use <code>removeAttribute</code> instead of setting the attribute value to <code>null</code> using <a href="/en/DOM/element.setAttribute" title="en/DOM/element.setAttribute">setAttribute</a>.</p>
<p>Attempting to remove an attribute that is not on the element doesn't raise an exception.</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-6D6AC0F9">DOM Level 2 Core: removeAttribute</a> (introduced in <a class="external" href="http://www.w3.org/TR/REC-DOM-Level-1/level-one-core.html#method-removeAttribute">DOM Level 1 Core</a>)</p>
<p>{{ languages( { "fr": "fr/DOM/element.removeAttribute", "ja": "ja/DOM/element.removeAttribute", "pl": "pl/DOM/element.removeAttribute" } ) }}</p>
Revert to this revision