TOC PREV NEXT INDEX

domref



length


length returns the number of items in a list.

Syntax

no_of_items = nodeList.length
 

Parameters

no_of_items is an integer value representing the number of items in a list.

Example

// all the paragraphs in the document
 
items = document.getElementsByTagName("p");
 
// are there any at all?
 
if ( items.length ) {
 
    // for each item in the list,
 
    // append the entire element as a string of HTML
 
    for (var i = 0; i < items.length; i++) {
 
        gross += items[0].innerHTML;
 
        // gross is now all the HTML for the paragraphs
 
    }
 
}
 

Notes

length is a very common property in DOM programming. It's very common to test the length of a list (to see if it exists at all) and to use it as the iterator in a for loop, as in the example above.

Specification

length
 


Netscape Communications
http://developer.netscape.com
TOC PREV NEXT INDEX