Table tbody Collection
Table Object
Definition and Usage
The tBodies collection returns a collection of <tbody> elements in a table.
Note:The elements in the collection are sorted in the order they appear in the source code.
Syntax
tableObject.tBodies
Properties
| Properties | Description |
|---|---|
| length | Returns the number of <tbody> elements in the collection. |
Methods
| Method | Description |
|---|---|
| [name_or_index] | An integer specifying the index of the element to retrieve (starting from 0) |
| item(name_or_index) | Returns the element at the specified index in the collection |
| namedItem(name) | Returns the element with the specified name in the collection |
Browser Support
![]()
![]()
![]()
![]()
![]()
All major browsers support the tBodies collection
Examples
Example
Display the number of tbodies in the table:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Rookie Tutorial (example.com)</title>
<script>
function displayResult(){
alert(document.getElementById("myTable").tBodies.length);
}
</script>
</head>
<body>
<table id="myTable" border="1">
<tbody>
<tr>
<td>cell 1</td>
<td>cell 2</td>
</tr>
</tbody>
<tbody>
<tr>
<td>cell 3</td>
<td>cell 4</td>
</tr>
</tbody>
</table>
<br>
<button type="button" onclick="displayResult()">Display the number of tbody elements in the table</button>
</body>
</html>
<html>
<head>
<meta charset="utf-8">
<title>Rookie Tutorial (example.com)</title>
<script>
function displayResult(){
alert(document.getElementById("myTable").tBodies.length);
}
</script>
</head>
<body>
<table id="myTable" border="1">
<tbody>
<tr>
<td>cell 1</td>
<td>cell 2</td>
</tr>
</tbody>
<tbody>
<tr>
<td>cell 3</td>
<td>cell 4</td>
</tr>
</tbody>
</table>
<br>
<button type="button" onclick="displayResult()">Display the number of tbody elements in the table</button>
</body>
</html>
Try it Yourself »
More Examples
Alert the content of the first row
Align cell content in table rows
Vertical alignment of cell content in table rows
Align the content of a single cell
Vertical alignment of cell content
Change the content of table cells
Table Object Other Extensions