← 返回首页
HTMLTableRowElement : propriété sectionRowIndex - Les API Web | MDN

Cette page a été traduite à partir de l'anglais par la communauté. Vous pouvez contribuer en rejoignant la communauté francophone sur MDN Web Docs.

View in English Always switch to English

HTMLTableRowElement : propriété sectionRowIndex

Baseline Large disponibilité

Cette fonctionnalité est bien établie et fonctionne sur de nombreux appareils et versions de navigateurs. Elle est disponible sur tous les navigateurs depuis juillet 2015.

La propriété en lecture seule sectionRowIndex de l'interface HTMLTableRowElement représente la position d'une ligne dans la section courante (<thead>, <tbody> ou <tfoot>).

Dans cet article

Valeur

L'index de la ligne, ou -1 si la ligne ne fait pas partie de la section.

Exemples

Cet exemple utilise JavaScript pour afficher le numéro de chaque ligne du tbody.

HTML

html
<table> <thead> <tr> <th>Article</th> <th>Prix</th> </tr> </thead> <tbody> <tr> <td>Bananes</td> <td>2 €</td> </tr> <tr> <td>Oranges</td> <td>8 €</td> </tr> <tr> <td>Filet de boeuf</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 = `(ligne n°${row.sectionRowIndex})`; row.appendChild(z); });

Résultat

Spécifications

Spécification
HTML
# dom-tr-sectionrowindex

Compatibilité des navigateurs

Activez JavaScript pour afficher ce tableau de compatibilité des navigateurs.

Voir aussi