HTML DOM Element removeAttributeNode()

Examples

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

const element = document.getElementsByTagName("H1")[0];

const attr = element.getAttributeNode("class");
element.removeAttributeNode(attr);
Try it Yourself »

Remove the href attribute node from a link:

const element = document.getElementById("myAnchor");

const attr = element.getAttributeNode("href");
element.removeAttributeNode(attr);
Try it Yourself »

Description

The removeAttributeNode() method removes an attribute from an element.

The removeAttributeNode() method returns an Attribute object.


The Difference Between removeAttribute() and removeAttributeNode()

The removeAttribute() method removes an attribute, and does not have a return value.

The removeAttributeNode() method removes an Attr object, and returns the removed object.

The result will be the same.




Syntax

element.removeAttributeNode(node)

Parameters

Parameter Description
attributenode Required.
The attribute node to remove.

Return Value

Type Description
ObjectAn Attr object representing the removed attribute.

Browser Support

element.removeAttributeNode() is a DOM Level 1 (1998) feature.

It is fully supported in all browsers:

Chrome Edge Firefox Safari Opera IE
Yes Yes Yes Yes Yes 9-11

Copyright 1999-2023 by Refsnes Data. All Rights Reserved.