Método XML DOM hasAttributes()
Definição e uso
Se o nó do elemento atual possui qualquer atributo, então hasAttributes()
O método retorna true, caso contrário, retorna false.
Sintaxe
hasAttributes()
Exemplo
O código a seguir carrega "books.xml" para xmlDoc e verifica se o primeiro elemento <book> possui qualquer 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(); {}