HTMLTableCellElement: cellIndex-Eigenschaft
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.
Die cellIndex
schreibgeschützte Eigenschaft des HTMLTableCellElement
Schnittstelle
repräsentiert die Position einer Zelle innerhalb ihrer Zeile (<tr>
). Die erste Zelle hat einen Index von 0
.
Wert
Gibt den Index der Zelle zurück oder -1
, wenn die Zelle nicht Teil einer Zeile ist.
Beispiele
Dieses Beispiel fügt allen Zellnummern der ersten Zeile des tbody
ein Label hinzu.
HTML
html
<table>
<thead>
<tr>
<th>Item</th>
<th>Price</th>
</tr>
</thead>
<tbody>
<tr>
<td>Bananas</td>
<td>$2</td>
</tr>
<tr>
<td>Rice</td>
<td>$2.5</td>
</tr>
</tbody>
</table>
JavaScript
js
const rows = document.querySelectorAll("tbody tr");
const cells = rows[0].cells;
for (const cell of cells) {
cell.textContent = `${cell.textContent} (cell #${cell.cellIndex})`;
}
Ergebnis
Spezifikationen
Specification |
---|
HTML # dom-tdth-cellindex |
Browser-Kompatibilität
Report problems with this compatibility data on GitHubdesktop | mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
cellIndex |
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.