Element.removeAttribute

  • Revision slug: DOM/element.removeAttribute
  • Revision title: element.removeAttribute
  • Revision id: 129723
  • Created:
  • Creator: Fredchat
  • Is current revision? No
  • Comment /* Adding fr */

Revision Content

{{template.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 align="left" width="200px"> 
document.getElementById("div1").removeAttribute("align"); 
// now: <div 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.

{{template.DOMAttributeMethods()}}

Specification

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

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

Revision Source

<p>
{{template.DomRef()}}
</p>
<h3 name="Summary"> Summary </h3>
<p><code>removeAttribute</code> removes an attribute from the specified element.
</p>
<h3 name="Syntax"> Syntax </h3>
<pre class="eval"><i>element</i>.removeAttribute(<i>attrName</i>) 
</pre>
<ul><li> <code>attrName</code> is a string that names the attribute to be removed from <i>element</i>.
</li></ul>
<h3 name="Example"> Example </h3>
<pre>// &lt;div align="left" width="200px"&gt; 
document.getElementById("div1").removeAttribute("align"); 
// now: &lt;div width="200px"&gt;
</pre>
<h3 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">setAttribute</a>.
</p><p>Attempting to remove an attribute that is not on the element doesn't raise an exception.
</p><p>{{template.DOMAttributeMethods()}}
</p>
<h3 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>{{ wiki.languages( { "fr": "fr/DOM/element.removeAttribute", "pl": "pl/DOM/element.removeAttribute" } ) }}
Revert to this revision