Método XML DOM hasAttributes()
❮ Objeto de nodo
Ejemplo
El siguiente fragmento de código carga " books.xml " en xmlDoc y devuelve si el primer elemento <book> tiene algún atributo:
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.hasAttributes();
}
Producción:
true
Definición y uso
El método hasAttributes() devuelve verdadero si el nodo especificado tiene algún atributo; de lo contrario, devuelve falso .
Nota: si el nodo especificado no es un nodo Elemento, el valor de retorno siempre es falso .
Compatibilidad con navegador
El método hasAttributes() es compatible con todos los navegadores principales.
Nota: Internet Explorer 9 y versiones anteriores no admiten el método hasAttributes().
Sintaxis
nodeObject.hasAttributes()
Parámetros
Ninguna.
Valor de retorno
Type | Description |
---|---|
Boolean | Returns true if the specified node has any attributes, otherwise false |
Detalles técnicos
Versión DOM | Objeto de nodo de nivel 2 básico |
---|
❮ Objeto de nodo