Tabla método createTHead()
Ejemplo
Cree un elemento <thead> (e inserte un elemento <tr> y <td> en él):
// Find a <table> element with id="myTable":
var table = document.getElementById("myTable");
// Create an empty <thead> element and add it to the table:
var header = table.createTHead();
// Create an empty <tr> element and add it to the first position of <thead>:
var row = header.insertRow(0);
// Insert a new cell (<td>) at the first position of the "new" <tr> element:
var cell = row.insertCell(0);
// Add some bold text in the new cell:
cell.innerHTML = "<b>This is a table header</b>";
Definición y uso
El método createTHead() crea un elemento <thead> vacío y lo agrega a la tabla.
Nota: si ya existe un elemento <thead> en la tabla, el método createTHead() devuelve el existente y no crea uno nuevo.
Nota: El elemento <thead> debe tener una o más etiquetas <tr> dentro.
Sugerencia: para eliminar el elemento <thead> de una tabla, utilice el método deleteTHead() .
Compatibilidad con navegador
Method | |||||
---|---|---|---|---|---|
createTHead() | Yes | Yes | Yes | Yes | Yes |
Sintaxis
tableObject.createTHead()
Parámetros
Ninguna |
Detalles técnicos
Valor devuelto: | El elemento <thead> recién creado (o existente) |
---|
Más ejemplos
Ejemplo
Crear y eliminar un elemento <thead>:
function myCreateFunction() {
var table = document.getElementById("myTable");
var header = table.createTHead();
var row = header.insertRow(0);
var cell = row.insertCell(0);
cell.innerHTML = "<b>This is a table header</b>";
}
function myDeleteFunction() {
document.getElementById("myTable").deleteTHead();
}
páginas relacionadas
Referencia HTML: etiqueta HTML <thead>
❮ Objeto de tabla