Metodo XML DOM removeAttribute()
❮ Oggetto Elemento
Esempio
Il seguente frammento di codice carica " books.xml " in xmlDoc e rimuove l'attributo "category" da tutti gli elementi <book>:
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');
}
Produzione:
cooking
null
Definizione e utilizzo
Il metodo removeAttribute() rimuove un attributo specificato.
Se in un DTD viene definito un valore predefinito per l'attributo, viene immediatamente visualizzato un nuovo attributo con il valore predefinito
Sintassi
elementNode.removeAttribute(name)
Parameter | Description |
---|---|
name | Required. Specifies the attribute to remove |
❮ Oggetto Elemento