XML DOM textContent Property

Node object reference manual

Definition and Usage

The textContent property can set or return the text content of a node and its descendants.

Regarding settings, any child node can be deleted and replaced by a single text node, and the content replaced is the string set by this property.

Syntax:

nodeObject.textContent

Example

In all examples, we will use the XML file books.xml, and JavaScript functions loadXMLDoc().

The following code snippet can return the text content of the <book> element:

xmlDoc=loadXMLDoc("books.xml");
var x=xmlDoc.getElementsByTagName('book');
for(i=0;i<x.length;i++)
  {
  document.write(x.item(i).textContent);
  document.write("<br />");
  }

Output:

Everyday Italian by Giada De Laurentiis 2005 30.00 
Harry Potter by J K. Rowling 2005 29.99 
XQuery Kick Start by James McGovern, Per Bothner, Kurt Cagle, James Linn
Vaidyanathan Nagarajan 2003 49.99 
Learning XML by Erik T. Ray 2003 39.95

Node object reference manual