XML DOM removeNamedItem() Method

NamedNodeMap Object Reference Manual

Definition and Usage

The removeNamedItem() method can delete the specified node.

If the deleted attribute has a default value, a new attribute will be immediately generated, including the namespace URI, local name, and prefix.

This method can return the deleted node.

Syntax:

removeNamedItem(nodename)
Parameter Description
nodename The name of the node to be deleted

Example

In all examples, we will use the XML file books.xml, and the JavaScript function loadXMLDoc().

The following code snippet can iterate over <book> elements and delete the category attribute:

xmlDoc=loadXMLDoc("books.xml");
var x=xmlDoc.getElementsByTagName('book');
for(i=0;i<x.length;i++)
  {
  x.item(i).attributes.removeNamedItem("category");
  }

Try It Yourself (TIY)

removeNamedItem() - Delete an item

NamedNodeMap Object Reference Manual