XML DOM textContent attribute

Definition and usage

The textContent attribute sets or returns the text content of the attribute.

Syntax:

attrObject.textContent

Example

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

The following code snippet returns the text content of the category attribute:

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

The output of the above code is:

children
cooking
web
web