DHTML Collections
Retrieves a collection of rows in a TABLE.
[ collRows = ] object.rows |
[ oObject = ] object.rows ( vIndex [ , iSubIndex ] ) |
collRows |
Reference to an array of elements contained by the object. |
oObject |
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. |
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. |
The scope of the rows collection is for the THEAD, TBODY, or TFOOT object of the table. In addition, there is also a rows collection for the TABLE object, which contains all the rows for the entire table.
A row that appears in one of the table sections also appears in the rows collection for TABLE. The TR object has two index properties, rowIndex and sectionRowIndex, which indicate where a given row appears.
The rowIndex property indicates where the TR appears with respect to the rows collection for the whole table. By contrast, sectionRowIndex returns where the TR appears with respect to the rows collection for the specific table section in which it is located.
If duplicate identifiers are found, a collection of those items is returned. Collections of duplicates must subsequently be referenced by ordinal position.
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
cells