JavaScript removeAttribute() method

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.

Syntax

Parameter Values

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.

Example1

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

Output

After the execution of the above code, the output will be -

JavaScript removeAttribute() method

After clicking the given button, we will see the following output -

JavaScript removeAttribute() method

Example2

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

Output

After the execution, the output will be -

JavaScript removeAttribute() method

After clicking the button, the output will be -

JavaScript removeAttribute() method

Similarly, we can use the removeAttribute() method to remove the target attribute, align attribute, readonly attribute, and many more.


Next TopicJavaScript reset




Contact US

Email:[email protected]

removeAttribute() method
10/30