XML DOM removeAttribute() Method

Definition and Usage

removeAttribute() Method to delete the specified attribute.

If the default value of an attribute is defined in the DTD, a new attribute with the default value will appear immediately.

Syntax

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

Example

The following code loads "books.xml" into xmlDoc and removes the "category" attribute from all <book> elements:

var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
   if (this.readyState == 4 && this.status == 200) {
       myFunction(this);
   }
};
xhttp.open("GET", "books.xml", true);
xhttp.send();
function myFunction(xml) {
    var xmlDoc = xml.responseXML;
    var x = xmlDoc.getElementsByTagName("book");
    document.getElementById("demo").innerHTML =
    x[0].getAttribute('category') + "<br>";
    x[0].removeAttribute('category');
    document.getElementById("demo").innerHTML +=;
    x[0].getAttribute('category');
}

Try It Yourself