Metoda removeAttribute() DOM XML
Definicja i użycie
removeAttribute()
Metoda usuwa określony atrybut.
Jeśli wartość domyślna atrybutu została zdefiniowana w DTD, natychmiast pojawi się nowy atrybut z wartością domyślną.
Gramatyka
elementNode.removeAttribute(name)
Parametry | Opis |
---|---|
name | Wymagane. Określa atrybut do usunięcia. |
Przykład
Poniższy kod załaduje "books.xml" do xmlDoc i usunie atrybut "category" ze wszystkich elementów <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'); }