HOME HTML CSS JAVASCRIPT SQL PHP JQUERY XML ASP.NET MORE...
REFERENCES | EXAMPLES | FORUM | ABOUT

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

Your suggestion:

Close [X]

Thank You For Helping Us!

Your message has been sent to W3Schools.

Close [X]
Search w3schools.com:

WEB BUILDING

Download XML Editor FREE Website BUILDER Free HTML5 Templates

SHARE THIS PAGE