Latest web development tutorials

HTML DOM Table createCaption () method

Table Object Reference Table Object

Definition and Usage

createCaption () method is used to get a table or create a <caption> element.

Note: If thecaption element in the table already exists, createCaption () method returns the existing title, rather than create a new one <caption> element.

Tip: Remove the table caption elements, use deleteCaption () method.

grammar

tableObject.createCaption()


Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support createCaption () method


Examples

Examples

The following example creates a table for the title:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>本教程(w3big.com)</title>
<script>
function displayResult(){
    var x=document.getElementById("myTable").createCaption();
    x.innerHTML="<b>我的表格标题</b>";
}
</script>
</head>
<body>

<table id="myTable" border="1">
    <tr>
        <td>cell 1</td>
        <td>cell 2</td>
    </tr>
    <tr>
        <td>cell 3</td>
        <td>cell 4</td>
    </tr>
</table>
<br>
<button type="button" onclick="displayResult()">创建一个表格标题</button>

</body>
</html>

try it"


Table Object Reference Table Object