"); x.textContent="hello"; document.write("After: "); document.write(x.textContent); The code above will output: Before: Everyday Italian Giada De Laurentiis 2005 30.00 After: hello [Try it Β»](#) * * Element Object](#)
Prop Element Textcontent
# XML DOM textContent Property
* * Element Object](#)
* * *
## Definition and Usage
The textContent property returns or sets the text of the selected element.
If returning text, the property returns the values of all text nodes within the element node.
If setting text, the property removes all child nodes and replaces them with a single text node.
## Syntax
Returning text:
elementNode.textContent
Setting text:
elementNode.textContent=string
* * *
## Tips and Notes
**Tip:** To set and return the text value of a node, use the (#) of the text node.
* * *
## Example 1
The following code snippet uses [loadXMLDoc()](#) to load "[books.xml](#)" into xmlDoc and gets the text node from the first element:
## Example
xmlDoc=loadXMLDoc("books.xml");
x=xmlDoc.getElementsByTagName("title");
document.write("Text Nodes: ");
document.write(x.textContent);
The code above will output:
Text Nodes: Everyday Italian
[Try it Β»](#)
* * *
## Example 2
The following code snippet uses [loadXMLDoc()](#) to load "[books.xml](#)" into xmlDoc, gets the text node from the first element, and replaces all nodes with a new text node:
## Example
xmlDoc=loadXMLDoc("books.xml"); x=xmlDoc.getElementsByTagName("book"); document.write("Before: "); document.write(x.textContent); document.write("
"); x.textContent="hello"; document.write("After: "); document.write(x.textContent); The code above will output: Before: Everyday Italian Giada De Laurentiis 2005 30.00 After: hello [Try it Β»](#) * * Element Object](#)
"); x.textContent="hello"; document.write("After: "); document.write(x.textContent); The code above will output: Before: Everyday Italian Giada De Laurentiis 2005 30.00 After: hello [Try it Β»](#) * * Element Object](#)
YouTip