Table captionProperty
Table Object
Definition and Usage
The caption property returns the caption element of the table.
The caption element defines the title of the table.
Note:The <caption> element defines a table caption. The <caption> tag must immediately follow the <table> tag, and each table can contain only one caption. Typically, the caption is centered above the table.
Syntax
tableObject.caption
Browser Support
![]()
![]()
![]()
![]()
![]()
All major browsers support the caption property.
Example
Example
The following example returns the text of the <caption> element of 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()">Show 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()">Show the number of tbody elements in the table</button>
</body>
</html>
Try it Yourself »
Table Object Other Extensions