Metoda tabulky createTHead().
Příklad
Vytvořte prvek <thead> (a vložte do něj prvky <tr> a <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>";
Definice a použití
Metoda createTHead() vytvoří prázdný prvek <thead> a přidá jej do tabulky.
Poznámka: Pokud prvek <thead> již v tabulce existuje, metoda createTHead() vrátí existující prvek a nevytvoří nový.
Poznámka: Element <thead> musí mít uvnitř jeden nebo více tagů <tr>.
Tip: Chcete-li odstranit prvek <thead> z tabulky, použijte metodu deleteTHead() .
Podpora prohlížeče
Method | |||||
---|---|---|---|---|---|
createTHead() | Yes | Yes | Yes | Yes | Yes |
Syntax
tableObject.createTHead()
Parametry
Žádný |
Technické údaje
Návratová hodnota: | Nově vytvořený (nebo existující) prvek <thead> |
---|
Další příklady
Příklad
Vytvořte a odstraňte prvek <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();
}
Související stránky
HTML reference: HTML značka <thead>
❮ Objekt tabulky