Método XML DOM hasAttributes()
❮ Objeto de nó
Exemplo
O fragmento de código a seguir carrega " books.xml " em xmlDoc e retorna se o primeiro elemento <book> tem algum 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();
}
Saída:
true
Definição e uso
O método hasAttributes() retorna true se o nó especificado tiver algum atributo, caso contrário, false .
Observação: se o nó especificado não for um nó Element, o valor de retorno será sempre false .
Suporte ao navegador
O método hasAttributes() é suportado em todos os principais navegadores.
Observação: o Internet Explorer 9 e versões anteriores não oferecem suporte ao método hasAttributes().
Sintaxe
nodeObject.hasAttributes()
Parâmetros
Nenhum.
Valor de retorno
Type | Description |
---|---|
Boolean | Returns true if the specified node has any attributes, otherwise false |
Detalhes técnicos
Versão DOM | Objeto de nó principal de nível 2 |
---|
❮ Objeto de nó