Table createCaption() method

Definition and Usage

createCaption() The method creates an empty The <caption> Element and add it to the table.

Note:If there is already a <caption> element in the table, then createCaption() The method returns the existing element and does not create a new element.

Tip:To remove the <caption> element from the table, use deleteCaption() method.

See also:

HTML Reference Manual:HTML <caption> Tag

Example

Example 1

Create a <caption> element with text for the table:

var table = document.getElementById("myTable").createCaption();
table.innerHTML = "<b>My table caption</b>";

Try It Yourself

Example 2

Create and delete <caption> elements:

function myCreateFunction() {
  var table = document.getElementById("myTable").createCaption();
  table.innerHTML = "<b>My table caption</b>";
}
function myDeleteFunction() {
  document.getElementById("myTable").deleteCaption();
}

Try It Yourself

Syntax

tableObject.createCaption()

Parameters

None.

Technical Details

Return Value: Newly created (or existing)The <caption> Element.

Browser Support

Chrome Edge Firefox Safari Opera
Chrome Edge Firefox Safari Opera
Support Support Support Support Support