Latest web development tutorials

XML DOM textContent property

Node Object Reference Node objects

Definition and Usage

textContent property sets or returns the text node and its descendants.

When set, any child nodes will be deleted and be replaced by a single Text node that contains the settings of the attribute string.

grammar

nodeObject.textContent


Examples

The following code fragment uses loadXMLDoc () to " the Books.xml " into xmlDoc, and returns the text content of <book> element:

Examples

xmlDoc=loadXMLDoc("books.xml");

x=xmlDoc.getElementsByTagName('book');

for(i=0;i<x.length;i++)
{
document.write(x.item(i).textContent);
document.write("
");
}

The code above will output:

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"

Try Demos

textContent - to set the text content of the node


Node Object Reference Node objects