Element: removeAttribute() method
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
TheElement methodremoveAttribute() removes the attribute with thespecified name from the element.
In this article
Syntax
js
removeAttribute(attrName)Parameters
attrNameA string specifying the name of the attribute to remove from theelement. If the specified attribute does not exist,
removeAttribute()returns without generating an error.
Return value
None (undefined).
Usage notes
You should useremoveAttribute() instead of setting the attribute value tonull either directly or usingsetAttribute().Many attributes will not behave as expected if you set them tonull.
Examples
js
// Given: <div disabled width="200px">document.getElementById("div1").removeAttribute("disabled");// Now: <div width="200px">Specifications
| Specification |
|---|
| DOM> # ref-for-dom-element-removeattribute①> |