Metodo XML DOM hasAttribute()
❮ Oggetto Elemento
Esempio
Il seguente frammento di codice carica " books.xml " in xmlDoc e controlla se il primo elemento <book> ha attributi di "categoria":
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");
}
L'output del codice sopra sarà:
true
Definizione e utilizzo
Il metodo hasAttribute() restituisce TRUE se il nodo dell'elemento corrente ha l'attributo specificato dal nome e FALSE in caso contrario.
Sintassi
hasAttribute(name)
Parameter | Description |
---|---|
name | Required. Specifies the attribute to find |
❮ Oggetto Elemento