Latest web development tutorials

HTML DOM Table caption property

Table Object Reference Table Object

Definition and Usage

caption property returns a table caption element.

caption element defines the table headers.

Note: <caption> element defines a table header.<Caption> tag must be immediately after the <table> tag, each table can only specify a caption. Typically, caption will be located above the center of the table position.

grammar

tableObject.caption


Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support caption property


Examples

Examples

The following example returns the form <caption> element of the text:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>本教程(w3big.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()">显示表中 tbody 元素的数目</button>

</body>
</html>

try it"


Table Object Reference Table Object