Metodo removeAttribute() del DOM XML
Definizione e uso
removeAttribute()
Metodo elimina l'attributo specificato.
Se l'attributo ha un valore predefinito definito nel DTD, apparirà immediatamente un nuovo attributo con il valore predefinito.
Sintassi
elementNode.removeAttribute(name)
Parametro | Descrizione |
---|---|
name | Obbligatorio. Specifica l'attributo da rimuovere. |
Esempio
Il seguente codice carica "books.xml" nel 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'); {}