XML DOM removeAttributeNode() Method
Definition and Usage
The removeAttributeNode() method removes the specified attribute node from the element.
Syntax:
elementNode.removeAttributeNode(node)
Parameters | Description |
---|---|
node | Required. The node to be removed. |
Return value
The removed Attr node.
Description
This method removes (and returns) an Attr node from the attribute collection of the current element. If the DTD has set a default value for the attribute to be removed, this method will add a new Attr node representing that default value. removeAttribute() MethodReplacing this method will often be simpler.
Example
In all examples, we will use the XML file books.xml, and JavaScript function loadXMLDoc().
The following code snippet removes the "category" attribute from all <book> elements in "books.xml":
xmlDoc=loadXMLDoc("books.xml");
x=xmlDoc.getElementsByTagName('book');
for(i=0;i<x.length;i++)
{
attnode=x.item(i).getAttributeNode("category");
old_att=x.item(i).removeAttributeNode(attnode)
;
document.write("Removed attribute: " + old_att.name + "<br />");
}
Output:
Removed attribute: category Removed attribute: category Removed attribute: category Removed attribute: category