THE WORLD'S LARGEST WEB DEVELOPER SITE
HTMLCSSJAVASCRIPTSQLPHPBOOTSTRAPJQUERYANGULARXML
 

Table createCaption() Method

Table Object Reference Table Object

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

Internet Explorer Firefox Opera Google Chrome Safari

The createCaption() method is supported in all major browsers.


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 Reference Table Object