Javascript Reference - HTML DOM removeAttributeNode() Method








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

The removeAttribute() method removes the attribute with the specified name, while removeAttributeNode() method removes the specified Attr object. The result will be the same.

Browser Support

removeAttributeNode Yes Yes Yes Yes Yes

Syntax

element.removeAttributeNode(attributenode)




Parameters

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

Return Value

The removed attribute node as Attr object

Example

The following code shows how to remove the style attribute node from a header element.


<!DOCTYPE html>
<html>
<body>
<h1 style="color:red">Hello World</h1>
<button onclick="myFunction()">test</button>
<!--from www  .  java  2s . c  o m-->
<script>
function myFunction()
{
    var n=document.getElementsByTagName("H1")[0];
    var a=n.getAttributeNode("style");
    n.removeAttributeNode(a);
}
</script>

</body>
</html>

The code above is rendered as follows: