Easy Tutorial
❮ Prop Element Prefix Dom Prop Document Stricterrorchecking ❯

XML DOM textContent Property



Definition and Usage

The textContent property sets or returns the text content of a node and its descendants.

When set, any child nodes are deleted and replaced by a single Text node containing the string that was set to this property.

Syntax


Example

The following code snippet uses loadXMLDoc() to load "books.xml" into xmlDoc and returns the text content of the <book> elements:

Example

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

The above code will output:


Try It

textContent - Set the text content of a node


❮ Prop Element Prefix Dom Prop Document Stricterrorchecking ❯