HTMLTableRowElement.rowIndex

Naši dobrovolníci ještě tento článek do jazyka Čeština nepřeložili. Přidejte se a pomozte nám tuto práci dokončit!
Tento článek si můžete přečíst také v jazyce English (US).

The HTMLTableRowElement.rowIndex read-only property represents the position of a row in relation to the whole <table>.

Even when the <thead>, <tbody>, and <tfoot> elements are out of order in the HTML, browsers render the table in the right order. Therefore the rows count from <thead> to <tbody>, from <tbody> to <tfoot>.

Syntax

var index = HTMLTableRowElement.rowIndex

Value

Returns the index of the row, or -1 if the row is not part of a table.

Example

This example uses JavaScript to label all the row numbers in a table.

HTML

<table>
  <thead>
    <tr><th>Item</th>        <th>Price</th></tr>
  </thead>
  <tbody>
    <tr><td>Bananas</td>     <td>$2</td></tr>
    <tr><td>Oranges</td>     <td>$8</td></tr>
    <tr><td>Top Sirloin</td> <td>$20</td></tr>
  </tbody>
  <tfoot>
    <tr><td>Total</td>       <td>$30</td></tr>
  </tfoot>
</table>

JavaScript

let rows = document.querySelectorAll('tr');

rows.forEach((row) => {
  let z = document.createElement("td");
  z.textContent = `(row #${row.rowIndex})`;
  row.appendChild(z);
});

Result

Browser compatibility

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidEdge MobileFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
Basic supportChrome Full support YesEdge Full support YesFirefox Full support 1IE Full support YesOpera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support 4Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yes

Legend

Full support  
Full support

Štítky a přispěvatelé do dokumentace

Přispěvatelé této stránky: mfluehr, connorshea, fscholz, teoli, kscarfone, Sheppy, darlesson
Poslední aktualizace od: mfluehr,