The length PropertyWe've already used the length property, which just returns the number of items in an array or collection. You can see the support for this property in Table 5.33. Table 5.33. The length Property
Here's an example from earlier in this chapter where we're using the length property of the children collection to loop over all the child HTML elements in a form: (Listing 05-05.html on the web site)<HTML> <HEAD> <TITLE>Using the children Property</TITLE> </HEAD> <BODY> <H1 NAME="header1">Using the children Property</H1> <FORM NAME="form1"> <INPUT NAME="button1" TYPE="BUTTON" ONCLICK="alerter()" VALUE="Click Me!"> <INPUT NAME="text1" TYPE="TEXT"> </FORM> <SCRIPT LANGUAGE="JavaScript"> <!-- for(var loopIndex=0; loopIndex < form1.children.length; loopIndex++){ document.write(form1.children[loopIndex].name + "<BR>") } // --> </SCRIPT> </BODY> </HTML> |