XML DOM textContent Property
Node Object
Example
The following code fragment loads "books.xml" into xmlDoc and returns the textual content of the <book> elements:
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
��� if (xhttp.readyState == 4 && xhttp.status == 200) {
������� myFunction(xhttp);
��� }
};
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).textContent
+ "<br>";
}
document.getElementById("demo").innerHTML = txt;
}
The output of the code above will be:
Everyday Italian Giada De Laurentiis 2005 30.00
Harry Potter J K. Rowling 2005 29.99
XQuery Kick Start James McGovern Per Bothner Kurt Cagle James Linn
Vaidyanathan Nagarajan 2003 49.99
Learning XML Erik T. Ray 2003 39.95
Try it yourself »
Definition and Usage
The textContent property sets or returns the textual content of a node and its descendants.
On setting, any child nodes are removed and replaced by a single Text node containing the string this property is set to.
Syntax
nodeObject.textContent
Try-It-Yourself Demos
textContent - Set the textual content of a node
Node Object