DHTML Collections
Retrieves a collection of all cells in a table row or in the entire TABLE.
[ oCellColl = ] object.oTR.cells |
[ oCellObject = ] object.cells ( vIndex [ , iSubIndex ] ) |
oCellColl |
Reference to an array of elements ( TD and TH ) contained by the object. If the object is a TR, the array contains elements only in that table row. If the object is a TABLE, the array contains all elements in the table. |
oCellObject |
Reference to an individual item in the array of elements contained by the object. |
vIndex |
Required. Number or string specifying the element or collection to retrieve. If this parameter is a number, the method returns the element in the collection at the given position, where the first element has value 0, the second has 1, and so on. If this parameter is a string and there is more than one element with the name or id property equal to the string, the method returns a collection of matching elements. The parameter can specify a string as a range of table rows and columns by providing a spreadsheet format such as "A1:B1". |
iSubIndex |
Optional. Position of an element to retrieve. This parameter is used when vIndex is a string. The method uses the string to construct a collection of all elements that have a name or id equal to the string and then retrieves from this collection the element at the position specified by iSubIndex. |
A cells collection is comprised of TH and TD objects.
When a cell spans multiple rows, that cell appears only in the cells collection for the first of the rows that the cell spans.
If duplicate identifiers are found, a collection of those items is returned. Collections of duplicates must subsequently be referenced by ordinal position.
Individual cells or an array of cells can be specified using a spreadsheet format. By specifying a colon-delimited string of the starting and ending cells, a cells collection can be retrieved from anywhere in the table. Specifying a particular cell with this format will return that object. The format of this string uses letters to indicate columns, starting with "A", and numbers to indicate rows, starting with 1. A cells collection on a table row will only include the elements within that row if the vIndex string specifies a range of multiple rows using the spreadsheet format.
The following example uses the rows and cells collections of a TABLE to insert a number into each cell of the table.
<html>
<script language="JScript">
function numberCells ( ) {
var count = 0;
var aRows = document.all.oTable.rows;
for ( i = 0; i < aRows.length; i ++ ) {
for ( j = 0; j < aRows ( i ).cells.length; j ++ ) {
aRows ( i ).cells ( j ).innerText = count;
count ++;
}
}
}
</script>
<body>
<table id="oTable" border=1 width=50% cols=4>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td></tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td></tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td> </td></tr>
</table>
<form><input type="Button" value="Do it!"
onclick="numberCells ( )"></form>
</body>
</html>
This feature requires Microsoft® Internet Explorer® 4 or later.
Show me
TABLE
rows