removeAttribute()
Last updated
Last updated
removeAttribute()
methodThe removeAttribute()
removes an attribute with a specified name from an element:
The removeAttribute()
accepts an argument which is the name of the attribute that you want to remove. If the attribute does not exist, the removeAttribute()
method wil not raise an error.
The removeAttribute()
returns a value of undefined
.
HTML elements have some attributes which are Boolean attributes. To set false
to the Boolean attributes, you cannot simply use the method, but you have to remove the attribute entirely using the removeAttribute()
method.
For example, the values of the disabled
attributes are true
in the following cases:
Similarly, the values of the following readonly
attributes are true
:
removeAttribute()
exampleThe following example uses the removeAttribute()
method to remove the target
attribute from the link element with the id js
:
How it works:
Select the link element with id js
using the querySelector()
method.
Remove the target
attribute by calling the removeAttribute()
on the selected link element.
Use the removeAttribute()
to remove an attribute from a specified element.
Setting the value of a Boolean attribute to false
will not work; use the removeAttribute()
method instead.