Método createTHead() da tabela
Exemplo
Crie um elemento <thead> (e insira um elemento <tr> e <td> nele):
// 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>";
Definição e uso
O método createTHead() cria um elemento <thead> vazio e o adiciona à tabela.
Nota: Se um elemento <thead> já existir na tabela, o método createTHead() retornará o existente e não criará um novo.
Nota: O elemento <thead> deve ter uma ou mais tags <tr> dentro.
Dica: Para remover o elemento <thead> de uma tabela, use o método deleteTHead() .
Suporte ao navegador
Method | |||||
---|---|---|---|---|---|
createTHead() | Yes | Yes | Yes | Yes | Yes |
Sintaxe
tableObject.createTHead()
Parâmetros
Nenhum |
Detalhes técnicos
Valor de retorno: | O elemento <thead> recém-criado (ou existente) |
---|
Mais exemplos
Exemplo
Crie e exclua um 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
Referência HTML: tag HTML <thead>
❮ Objeto de Tabela