XML DOM text attribute

Definition and usage

The text attribute returns the value of all text nodes selected.

Syntax:

elementNode.text

Tips and comments:

Tip:To return the text node text for Mozilla browsers, use the textContent property.

Examples

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

The following code snippet retrieves the text node of the first <title> element in "books.xml":

xmlDoc=loadXMLDoc("books.xml");
var x=xmlDoc.getElementsByTagName("title")[0];
document.write("Text Nodes: ");
document.write(x.text);

The output of the above code is:

Text Nodes: Everyday Italian