HTMLTableRowElement: sectionRowIndex property
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
The sectionRowIndex
read-only property of the HTMLTableRowElement
interface
represents the position of a row within the current section (<thead>
, <tbody>
, or <tfoot>
).
Value
The index of the row, or -1
if the row is not part of the section.
Examples
This example uses JavaScript to label all the row numbers of the tbody
.
HTML
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
js
const rows = document.querySelectorAll("tbody tr");
rows.forEach((row) => {
const z = document.createElement("td");
z.textContent = `(row #${row.sectionRowIndex})`;
row.appendChild(z);
});
Result
Specifications
Specification |
---|
HTML # dom-tr-sectionrowindex |
Browser compatibility
Report problems with this compatibility data on GitHubdesktop | mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
sectionRowIndex |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.