XML DOM textContent property
Definition and Usage
textContent property returns or sets the text of the selected element.
If the text is returned, the property returns the value of all text nodes within element nodes.
If you set the text, the attribute delete all child nodes and nodes with a single text to replace them.
grammar
Back text:
Set the text:
Tips and Notes
Tip: To set the value of the node and returns the text, use the text node nodeValue property .
Example 1
The following code fragment uses loadXMLDoc () to " the Books.xml " into xmlDoc and get text nodes from the first <title> element:
Examples
x=xmlDoc.getElementsByTagName("title")[0];
document.write("Text Nodes: ");
document.write(x.textContent);
The code above will output:
try it"
Example 2
The following code fragment uses loadXMLDoc () to " the Books.xml " into xmlDoc get text nodes from the first <book> element and replace all the nodes into a new text node:
Examples
x=xmlDoc.getElementsByTagName("book")[0];
document.write("Before: ");
document.write(x.textContent);
document.write("
");
x.textContent="hello";
document.write("After: ");
document.write(x.textContent);
The code above will output:
After: hello
try it"
Element object