Tabella createTHead() Metodo
Esempio
Crea un elemento <thead> (e inserisci un elemento <tr> e <td>):
// 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>";
Definizione e utilizzo
Il metodo createTHead() crea un elemento <thead> vuoto e lo aggiunge alla tabella.
Nota: se nella tabella esiste già un elemento <thead>, il metodo createTHead() restituisce quello esistente e non ne crea uno nuovo.
Nota: l'elemento <thead> deve avere uno o più tag <tr> all'interno.
Suggerimento: per rimuovere l'elemento <thead> da una tabella, utilizzare il metodo deleteTHead() .
Supporto browser
Method | |||||
---|---|---|---|---|---|
createTHead() | Yes | Yes | Yes | Yes | Yes |
Sintassi
tableObject.createTHead()
Parametri
Nessuno |
Dettagli tecnici
Valore di ritorno: | L'elemento <thead> appena creato (o esistente). |
---|
Altri esempi
Esempio
Crea ed elimina 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();
}
Pagine correlate
Riferimento HTML: tag HTML <thead>
❮ Oggetto tabella