cellscells*
*Contents  *Index  *Topic Contents
*Previous Topic: areas
*Next Topic: children

cells

Description

Retrieves a collection of all cells in the row of a table. This is a collection of TH and TD elements.

Note When a cell spans multiple rows, that cell appears only in the cells collection for the first of the rows that the cell spans.

Syntax

object.cells(index)

ParameterDescription
objectA TR element.
indexOptional. An integer or a string specifying the index value of the element to retrieve. Integer indexes are zero-based, meaning the first element in the collection has index 0. A string index is valid only if the string is an identifier of at least one element in the document.

Remarks

If duplicate identifiers are found, a collection of those items is returned. Collections of duplicates must subsequently be referenced by ordinal position.

Example

The following example uses the rows collection on the TABLE and the cells collection to insert a number into each cell of the table.

<HTML>
<SCRIPT LANGUAGE="JScript">
function numberCells() {
    var count=0;
    for (i=0; i < document.all.mytable.rows.length; i++) {
        for (j=0; j < document.all.mytable.rows(i).cells.length; j++) {
            document.all.mytable.rows(i).cells(j).innerText = count;
            count++;
        }
    }
}
</SCRIPT>
<BODY onload="numberCells()">
<TABLE id=mytable border=1>
<TR><TH>&nbsp;</TH><TH>&nbsp;</TH><TH>&nbsp;</TH><TH>&nbsp;</TH></TR>
<TR><TD>&nbsp;</TD><TD>&nbsp;</TD><TD>&nbsp;</TD><TD>&nbsp;</TD></TR>
<TR><TD>&nbsp;</TD><TD>&nbsp;</TD><TD>&nbsp;</TD><TD>&nbsp;</TD></TR>
</TABLE>
</BODY>
</HTML> 

Applies To

TR

Property

length

Methods

item, tags


Up Top of Page
© 1997 Microsoft Corporation. All rights reserved. Terms of Use.