You are here: Reference > JavaScript > client-side > HTML DOM > properties > length (comment, CommentNode, TextNode)

length property (comment, CommentNode, TextNode)

Browser support:
Returns the number of characters within a TextNode, CommentNode or comment object.
To get the contents of the objects mentioned above, use the data property.


You can find the related objects in the Supported by objects section below.
This property is read-only.

Possible values:

Integer that represents the length of the contents.
Default: this property has no default value.

Example HTML code 1:

This example illustrates the use of the length property:
    <script type="text/javascript">
        function GetCountOfChars () {
            var span = document.getElementById ("mySpan");
            var textNode = span.firstChild;
            alert (textNode.length);
    <span id="mySpan">AAA-BBB-CCC</span>
    <br />
    <button onclick="GetCountOfChars ()">Get the number of chars in a TextNode!</button>
Did you find this example helpful? yes no

Supported by objects:

Related pages:

External links:

User Contributed Comments

Post Content

Post Content