JavaScript removeAttribute() Method Tutorial

In this section, we will learn what the removeAttribute() method is and how to use it in JavaScript.

What is Element removeAttribute() Method in JavaScript?

The JavaScript Element removeAttribute() method is used to remove an attribute of an HTML element.

There’s another method called removeAttributeNode() which is used for the same purpose; except the removeAttribute() method takes the name of an attribute as a string value while the removeAttributeNode() method takes a reference to the object that represents the target attribute node. Also, the removeAttribute() method does not return a value. But the removeAttributeNode() method will return a reference to the attribute that was removed.

Note: you can use the setAttribute() method to set a new attribute for an element.

JavaScript removeAttribute() Method Syntax:

element.removeAttribute(att-name)

JavaScript removeAttribute() Method Parameter

The method takes one argument and that is the name of the attribute we want to remove.

JavaScript removeAttribute() Method Return Value

The method does not return a value.

Example: JavaScript remove attribute

See the Pen JavaScript remove attribute by Omid Dehghan (@odchan1) on CodePen.

Leave a Reply