Método XML DOM hasAttribute()

Definição e Uso

Se o nó de elemento atual possui o atributo com o nome especificado, então hasAttribute() O método retorna true, caso contrário retorna false.

Sintaxe

hasAttribute(name)
Parâmetros Descrição
name Obrigatório. Especifica o atributo a ser procurado.

Exemplo

Abaixo está o código que carrega "books.xml" para xmlDoc e verifica se o primeiro elemento <book> possui qualquer atributo "category":

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");
}

Experimente pessoalmente