XML DOM removeNamedItem() Method
Definition and Usage
removeNamedItem()
This method deletes the specified node.
If the deleted attribute has a default value, a new attribute with the default value, namespace URI, local name, and prefix (if any) will appear immediately.
This method returns the node that was removed.
Syntax
removeNamedItem(nodename)
Parameters | Description |
---|---|
nodename | The name of the node to be deleted. |
Example
The following code loads "books.xml" into xmlDoc, loops through the <book> elements, and removes the category attribute:
function myFunction(xml) { var xmlDoc = xml.responseXML; var txt = ""; var x = xmlDoc.getElementsByTagName('book'); txt += x.item(0).attributes.length + "<br>"; x.item(0).attributes.removeNamedItem("category"); txt += x.item(0).attributes.length; document.getElementById("demo").innerHTML = txt; {}