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, along with the namespace URI, local name, and prefix.

This method can return the deleted node.

Syntax:

removeNamedItem(nodename)
Parameters Description
nodename Node name to be deleted

Example

In all examples, we will use the XML file books.xml, and JavaScript functions 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");
  }

NamedNodeMap object reference manual