XML DOM length attribute
Definition and Usage
The length attribute returns the length of the node's text (in characters).
Syntax:
textNode.length
Example
In all examples, we will use the XML file books.xml, and JavaScript function loadXMLDoc().
The following code snippet outputs the text node data and length of the first <title> element in "books.xml":
xmlDoc=loadXMLDoc("books.xml");
x=xmlDoc.getElementsByTagName("title")[0].childNodes[0];
document.write(x.data);
document.write(" - Length: ");
document.write(x.length
);
Output:
Everyday Italian - Length: 16