XML DOM removeAttribute() Method

Definition and usage

The removeAttribute() method deletes the specified attribute. If the document type declaration (DTD) has set a default value for the specified attribute, then the subsequent call getAttribute() methodThe default value will be returned.

Operations to delete non-existing attributes or attributes that are not set but have default values will be ignored.

Syntax:

elementNode.removeAttribute(name)
Parameter Description
name Required. Specifies the name of the attribute to be deleted.

Example

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

The following code snippet deletes the "category" attribute of all <book> elements in "books.xml":

xmlDoc=loadXMLDoc("books.xml");
x=xmlDoc.getElementsByTagName('book');
for (i=0;i<x.length;i++)
{
x[i].removeAttribute('category'));
}