--- title: HTMLTableRowElement.rowIndex slug: Web/API/HTMLTableRowElement/rowIndex tags: - rowIndex - table - tr translation_of: Web/API/HTMLTableRowElement/rowIndex ---

概要

このプロパティは、テーブル全体に関連して 行 (row) の 位置 (index) を {{htmlelement("thead")}} 、{{htmlelement("tbody")}} 、{{htmlelement("tfoot")}} の順序で取得します。

※Opera は前述の順序ではなく、 HTML 中の記述順で rowIndex を取得します。

<table>
	<thead>
		<tr>
			<th>品目</th>
			<th>価格</th>
		</tr>
	</thead>
	<tbody>
		<tr>
			<td>抹茶プリン</td>
			<td>250 円</td>
		</tr>
		<tr>
			<td>カスタードプリン</td>
			<td>200 円</td>
		</tr>
		<tr>
			<td>牛乳プリン</td>
			<td>150 円</td>
		</tr>
	</tbody>
	<tfoot>
		<tr>
			<td>小計</td>
			<td>600 円</td>
		</tr>
	</tfoot>
</table>

rowIndex の値を表示する例を以下に示します。

var rows = document.getElementsByTagName('tr');

for(var x = 0, xLength = rows.length; x < xLength; x++) {
  alert('rowIndex=' + rows[x].rowIndex);
}

互換性

Quirksmode.org の rowIndex browser compatibility を参照して下さい。