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 of the text node for Mozilla browsers, use the textContent property.
Example
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