Table createCaption() Method
Example
Create a <caption> element with some text for a table:
var table = document.getElementById("myTable").createCaption();
table.innerHTML =
"<b>My table caption</b>";
Try it Yourself »
Definition and Usage
The createCaption() method creates an empty <caption> element and adds it to the table.
Note: If a <caption> element already exists on the table, the createCaption() method returns the existing one, and does not create a new one.
Tip: To remove the <caption> element from a table, use the deleteCaption() method.
Browser Support
Method | |||||
---|---|---|---|---|---|
createCaption() | Yes | Yes | Yes | Yes | Yes |
Syntax
tableObject.createCaption()
Parameters
None |
Technical Details
Return Value: | The newly created (or an existing) <caption> element |
---|
More Examples
Example
Create and delete a <caption> element:
function myCreateFunction() {
var table = document.getElementById("myTable").createCaption();
table.innerHTML = "<b>My table caption</b>";
}
function
myDeleteFunction() {
document.getElementById("myTable").deleteCaption();
}
Try it Yourself »
Related Pages
HTML reference: HTML <caption> tag
Table Object