Element removeAttributeNode() Method - Javascript DOM

Javascript examples for DOM:Element removeAttributeNode

Description

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

Parameter Values

Parameter TypeDescription
attributenode Attr object Required. The attribute node

Return Value:

An Attr object, representing the removed attribute node

The following code shows how to Remove the href attribute node from an <a> element:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<a id="myAnchor" href="http://www.java2s.com">A Link: go to java2s.com</a>

<button onclick="myFunction()">Test</button>

<script>
function myFunction() {//from   ww w  .jav a 2  s  .  com
    var elmnt = document.getElementById("myAnchor");
    var attr = elmnt.getAttributeNode("href");
    elmnt.removeAttributeNode(attr);
}
</script>

</body>
</html>

Related Tutorials