JavaScript removeAttribute() methodThis 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. SyntaxParameter Valuesattributename: 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. Example1In 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 NowOutput After the execution of the above code, the output will be - After clicking the given button, we will see the following output - Example2In 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 NowOutput 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. Next TopicJavaScript reset |
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India