XML DOM hasAttribute() Metode
❮ Elementvoorwerp
Voorbeeld
TDie volgende kodefragment laai " books.xml " in xmlDoc en kyk of die eerste <boek>-element enige "kategorie"-kenmerke het:
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")[0];
document.getElementById("demo").innerHTML =
x.hasAttribute("category");
}
Die afvoer van die kode hierbo sal wees:
true
Definisie en gebruik
Die hasAttribute() metode gee TRUE terug as die huidige element nodus die kenmerk het wat by naam gespesifiseer is, en FALSE anders.
Sintaksis
hasAttribute(name)
Parameter | Description |
---|---|
name | Required. Specifies the attribute to find |
❮ Elementvoorwerp