X
HOME HTML5 CSS3 JAVASCRIPT SQL PHP5 JQUERY ANGULAR BOOTSTRAP3 XML MORE...
REFERENCES | EXAMPLES | FORUM | ABOUT

HTML DOM removeAttribute() Method

Element Object Reference 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 w3schools.com

Try it yourself »


Related Pages

HTML Tutorial: HTML Attributes

HTML DOM Reference: hasAttribute() Method

HTML DOM Reference: getAttribute() Method

HTML DOM Reference: setAttribute() Method


Element Object Reference Element Object


Your suggestion:

Close [X]

Thank You For Helping Us!

Your message has been sent to W3Schools.

Close [X]
Search w3schools.com:

WEB HOSTING

UK Reseller Hosting

WEB BUILDING

Download XML Editor FREE Website BUILDER Free HTML5 Templates

SHARE THIS PAGE

facebook