XML DOM length attribute
Definition and Usage
length
The attribute returns the number of characters in the selected node.
Syntax
CDATANode.length
Example
Below code loads "books_cdata.xml" into xmlDoc and retrieves the text node data and length from the first <title> element:
var xhttp = new XMLHttpRequest(); xhttp.onreadystatechange = function() { if (this.readyState == 4 && this.status == 200) { myFunction(this); } }; xhttp.open("GET", "books_cdata.xml", true); xhttp.send(); function myFunction(xml) { var xmlDoc = xml.responseXML; var x = xmlDoc.getElementsByTagName("html")[0].childNodes[0]; document.getElementById("demo").innerHTML = x.data + " - Lengte: " + x.length; }
Onthoud dat de bovenstaande lengte afkomstig is van het hele CDATA gedeelte (bvb. <b>verbluffend!</b>), en niet alleen van de tekst.