Propriedade XML DOM textContent
❮ Objeto de Atração
Exemplo
O fragmento de código a seguir carrega " books.xml " em xmlDoc e retorna o conteúdo textual dos atributos de 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 x, i, xmlDoc, txt;
xmlDoc = xml.responseXML;
txt = "";
x = xmlDoc.getElementsByTagName('book');
for (i = 0; i < x.length; i++) {
txt += x.item(i).attributes[0].textContent + "<br>";
}
document.getElementById("demo").innerHTML = txt;
}
Saída:
cooking
children
web
web
Definição e uso
A propriedade textContent define ou retorna o conteúdo textual de um atributo.
Sintaxe
attrObject.textContent
Demonstrações de teste você mesmo
❮ Objeto de Atração