This page is Ready to Use

Notice: The WebPlatform project, supported by various stewards between 2012 and 2015, has been discontinued. This site is now available on github.

length

Summary

Gets the number of characters in a text node.

Property of dom/CharacterDatadom/CharacterData

Syntax

Note: This property is read-only.

var textLength = textualNode.length;

Return Value

Returns an object of type NumberNumber

The number of characters in the node.

Examples

//create text node
var phrase = document.createTextNode ("A flawed plan today is better than a perfect plan tomorrow.");
//report length
alert(phrase.length);

This example uses the length property to specify where a Text node is split by using the splitText method.

<script>
function fnChangeValue(){
   var oListItem = document.createElement("LI");
   var oList = document.getElementById("oList");
   oList.appendChild(oListItem);
   var oNode = oList.firstChild.childNodes(0);
   var oTextNode = oList.firstChild.childNodes(0);
   var oSplit = oTextNode.splitText(oTextNode.length/2);
   oListItem.appendChild(oSplit);
}
</script>
<ul id="oList" onclick="fnChangeValue()">
<li>Start Here</li>
</ul>

Related specifications

DOM Level 1
Recommendation

Attributions