XML DOM data attribute

Definition and usage

The data attribute sets or returns the text of an element or attribute.

Syntax:

textNode.data

Example

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

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

xmlDoc=loadXMLDoc("books.xml");
x=xmlDoc.getElementsByTagName("title")[0].childNodes[0];
document.write(x.data;

Output:

Everyday Italian