JavaScript’s Element.removeAttribute()
method removes an attribute from the Element
.
Syntax
Element.removeAttribute(parameter);
Parameters
A string containing the name of the attribute to remove from the element.
Return value
The removeAttribute()
method does not have a return value, which means that the method implicitly returns undefined
.
Examples
Here is an example of using the JavaScript removeAttribute()
method.
Consider the following line of HTML:
<a href="https://javascriptguide.com" target="_blank">JavaScript Guide</a>
How can we remove the target
attribute with JavaScript?
Well, we can select the a
element with the querySelector()
method and use the removeAttribute()
method:
let a = document.querySelector('a');
a.removeAttribute('target');
This is how our HTML looks like now:
<a href="https://javascriptguide.com">JavaScript Guide</a>
Browser compatibility
Chrome
|
Edge
|
Firefox
|
Internet Explorer
|
Opera
|
Safari
|
Chrome (Android)
|
Firefox (Android)
|
Opera (Android)
|
Safari (iOS)
|
Samsung Internet
|
WebView (Android)
|
|
---|---|---|---|---|---|---|---|---|---|---|---|---|
removeAttribute() |
1 | 12 | 1 | 5 | 8 | 1 | 18 | 4 | 10.1 | 1 | 1.0 | 4.4 |