Método createCaption() de la tabla

Definición y uso

createCaption() El método crea un elemento Elemento <caption> y agregarlo a la tabla.

Notas:Si ya existe un elemento <caption> en la tabla, createCaption() El método devuelve el elemento existente y no crea un nuevo elemento.

Consejo:Para eliminar un elemento <caption> de la tabla, utilice Método deleteCaption().

Vea también:

Manual de referencia HTML:Etiqueta <caption> de HTML

Ejemplo

Ejemplo 1

Crear un elemento <caption> con texto para la tabla:

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

Intente hacerlo usted mismo

Ejemplo 2

Crear y eliminar elementos <caption>:

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

Intente hacerlo usted mismo

Sintaxis

tableObject.createCaption()

Parámetros

Sin.

Detalles técnicos

Valor devuelto: Recién creado (o existente)Elemento <caption>.

Compatibilidad del navegador

Chrome Edge Firefox Safari Opera
Chrome Edge Firefox Safari Opera
Soporte Soporte Soporte Soporte Soporte