This page is In Progress

Notice: The WebPlatform project, supported by various stewards between 2012 and 2015, has been discontinued. This site is now available on github.


Property of dom/HTMLElementdom/HTMLElement


var result = element.rows;
element.rows = value;


This example shows how to use the rows and cells collections to insert a number into each cell of the table.

<SCRIPT type="text/javascript">
function numberCells()
    var count=1;
    var oTable = document.getElementById('oTable');
    var RowsLength = oTable.rows.length;
    for (var i=0; i < RowsLength; i++)
        var oCells = oTable.rows.item(i).cells;
        var CellsLength = oCells.length;
        for (var j=0; j < CellsLength; j++)
            oCells.item(j).innerHTML = count++;
<BODY onload="numberCells()">
<TABLE id=oTable border=1>
<TR><TH> </TH><TH> </TH><TH> </TH><TH> </TH></TR>
<TR><TD> </TD><TD> </TD><TD> </TD><TD> </TD></TR>
<TR><TD> </TD><TD> </TD><TD> </TD><TD> </TD></TR>

View live example



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 the table. The tr object has two index properties, rowIndex and sectionRowIndex, that 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 be referenced subsequently by ordinal position.


Standards information

There are no standards that apply here.