Latest web development tutorials
 

HTML DOM removeAttribute() Method

< Element Object

Example

Remove the class attribute from an <h1> element:

document.getElementsByTagName("H1")[0].removeAttribute("class");

Before removing the attribute:

Hello World

After removing the attribute:

Hello World

Try it Yourself »

Definition and Usage

The removeAttribute() method removes the specified attribute from an element.

The difference between this method and the removeAttributeNode() method is that the removeAttributeNode() method removes the specified Attr object, while this method removes the attribute with the specified name. The result will be the same. Also this method has no return value, while the removeAttributeNode() method returns the removed attribute, as an Attr object.

Tip: Use the getAttribute() method to return the value of an attribute of an element.

Tip: Use the setAttribute() method to add an attribute to an element.


Browser Support

Method
removeAttribute() Yes Yes Yes Yes Yes

Syntax

element.removeAttribute(attributename)

Parameter Values

Parameter Type Description
attributename String Required. The name of the attribute you want to remove

Technical Details

Return Value: No return value
DOM Version Core Level 1 Element Object

Examples

More Examples

Example

Remove the href attribute from an <a> element:

document.getElementById("myAnchor").removeAttribute("href");

Before removing the attribute:

After removing the attribute:

Go to w3ii.com
Try it Yourself »

Related Pages

HTML Tutorial: HTML Attributes

HTML DOM Reference: href="met_element_hasattribute.html">hasAttribute() Method

HTML DOM Reference: href="met_element_getattribute.html">getAttribute() Method

HTML DOM Reference: href="met_element_setattribute.html">setAttribute() Method


< Element Object