テーブルtBodiesコレクション
例
テーブルにある<tbody>要素の数を調べます。
var x = document.getElementById("myTable").tBodies.length;
xの結果は次のようになります。
2
以下の「自分で試してみてください」の例をもっと見てください。
定義と使用法
tBodiesコレクションは、テーブル内のすべての<tbody>要素のコレクションを返します。
注:コレクション内の要素は、ソースコードに表示されるとおりに並べ替えられます。
ブラウザのサポート
Collection | |||||
---|---|---|---|---|---|
tBodies | Yes | Yes | Yes | Yes | Yes |
構文
tableObject.tBodies
プロパティ
Property | Description |
---|---|
length | Returns the number of <tbody> elements in the collection. Note: This property is read-only |
メソッド
Method | Description |
---|---|
[index] | Returns the <tbody> element from the collection with the specified index (starts at 0). Note: Returns null if the index number is out of range |
item(index) | Returns the <tbody> element from the collection with the specified index (starts at 0). Note: Returns null if the index number is out of range |
namedItem(id) | Returns the <tbody> element from the collection with the specified id. Note: Returns null if the id does not exist |
技術的な詳細
DOMバージョン: | コアレベル2ドキュメントオブジェクト |
---|---|
戻り値: | <table>要素内のすべての<tbody>要素を表すHTMLCollectionオブジェクト。コレクション内の要素は、ソースコードに表示されるとおりに並べ替えられます |
その他の例
例
[インデックス]
テーブルの最初の<tbody>要素(インデックス0)のinnerHTMLに警告します。
alert(document.getElementById("myTable").tBodies[0].innerHTML;
例
item(インデックス)
テーブルの最初の<tbody>要素(インデックス0)のinnerHTMLに警告します。
alert(document.getElementById("myTable").tBodies.item(0).innerHTML);
例
namedItem(id)
テーブル内のid = "myTBody"を使用して<tbody>要素のinnerHTMLに警告します。
alert(document.getElementById("myTable").tBodies.namedItem("myTBody").innerHTML);
関連ページ
HTMLリファレンス:HTML <tbody>タグ
❮テーブルオブジェクト