XML DOM removeAttribute() Method
❮ 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 (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');
}
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