EN
Ce contenu n’est pas disponible dans votre langue. Voici la version anglaise.

rowIndex property

Retrieves the position of the object in the rows collection for the table.

Syntax

JavaScript

p = object.rowIndex

Property values

Type: Integer

Integer that specifies the index number.

Standards information

Remarks

This property is different from sectionRowIndex, which indicates the object's position in the tBody, tHead, or tFoot rows collection. These sections are mutually exclusive, so the tr is always contained in one of these sections and in the table. You can determine the rowIndex property of an object by the order in which the object appears in the HTML source.

Examples

This example function shows how to use the rowIndex attribute to format a table. The function sets the background color of the rows in the table to black or white, alternating row by row.


function formatTable(oTable)
{
  var rows=oTable.rows;
  for(var i=0;i<rows.length;i++)
  {
    if(i%2==0) {
      rows[i].style.backgroundColor = "black";
      rows[i].style.color = "white";
    } else {
      rows[i].style.backgroundColor = "white";
      rows[i].style.color = "black";
    }
  }
}

See also

tr
Reference
cellIndex
sourceIndex

 

 

Afficher:
© 2014 Microsoft