THE WORLD'S LARGEST WEB DEVELOPER SITE
HTMLCSSJAVASCRIPTSQLPHPBOOTSTRAPJQUERYANGULARXML
 

XML DOM removeAttribute() Method


Element Object Reference Element Object

Example

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

var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
    if (xhttp.readyState == 4 && xhttp.status == 200) {
        myFunction(xhttp);
    }
};
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');
}

Output:

cooking
null
Try it Yourself »

Definition and Usage

The removeAttribute() method removes a specified attribute.

If a default value for the attribute is defined in a DTD, a new attribute immediately appears with the default value

Syntax

elementNode.removeAttribute(name)

Parameter Description
name Required. Specifies the attribute to remove

Element Object Reference Element Object