This method is used to remove the specified attribute from the element. It is different from the removeAttributeNode() method. The removeAttributeNode() method removes the particular Attr object, but the removeAttribute() method removes the attribute with the specified name.
attributename: It is the required parameter that specifies the attribute's name to remove from the element. If the attribute doesn't exist, the method doesn't create any error.
Let us understand it by using some examples.
In this example, there are two paragraph elements with id para, and para1 belongs to the same class jtp. Here, we are removing the class attribute of these paragraph elements. We have to click the given HTML button to see the effect.Test it Now
After the execution of the above code, the output will be -
After clicking the given button, we will see the following output -
In this example, there are two div elements with id div1 and div2. We are applying the style attribute to these div elements.
Here, we are removing the style attribute of these div elements. We have to click the given HTML button to see the effect.Test it Now
After the execution, the output will be -
After clicking the button, the output will be -
Similarly, we can use the removeAttribute() method to remove the target attribute, align attribute, readonly attribute, and many more.