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.
removeAttributeNode |
Yes | Yes | Yes | Yes | Yes |
element.removeAttributeNode(attributenode)
Parameter | Type | Description |
---|---|---|
attributenode | Attr object | Required. The attribute node to remove |
The removed attribute node as Attr object
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: