THE WORLD'S LARGEST WEB DEVELOPER SITE
HTMLCSSJAVASCRIPTSQLPHPBOOTSTRAPJQUERYANGULARXML
 

HTML DOM removeAttributeNode() Method

Element Object Reference Element Object

Example

Remove the class attribute node from an <h1> element:

var elmnt = document.getElementsByTagName("H1")[0];  // Get the first <h1> element in the document
var attr = elmnt.getAttributeNode("class");          // Get the class attribute node from <h1>
elmnt.removeAttributeNode(attr);                     // Remove the class attribute node from <h1>

Before removing the attribute node:

Hello World

After removing the attribute node:

Hello World

Try it yourself »

Definition and Usage

The removeAttributeNode() method removes the specified attribute from an element, and returns the removed attribute, as an Attr Node object.

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

Tip: Use the getAttributeNode() method to return an attribute node of an element.

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


Browser Support

Method
removeAttributeNode() Yes Yes Yes Yes Yes

Syntax

element.removeAttributeNode(attributenode)

Parameter Values

Parameter Type Description
attributenode Attr object Required. The attribute node you want to remove

Technical Details

Return Value: An Attr object, representing the removed attribute node
DOM Version Core Level 1 Element Object

Examples

More Examples

Example

Remove the href attribute node from an <a> element:

var elmnt = document.getElementById("myAnchor");   // Get the <a> element with id="myAnchor"
var attr = elmnt.getAttributeNode("href");         // Get the href attribute node from <a>
elmnt.removeAttributeNode(attr);                   // Remove the href attribute node from <a>

Before removing the attribute node:

After removing the attribute node:

Go to w3schools.com
Try it yourself »

Related Pages

HTML Tutorial: HTML Attributes

HTML DOM Reference: The HTML DOM Attribute Object

HTML DOM Reference: removeAttribute() Method

HTML DOM Reference: getAttributeNode() Method

HTML DOM Reference: setAttributeNode() Method


Element Object Reference Element Object