Tabelle createTHead() Methode
Beispiel
Erstellen Sie ein <thead>-Element (und fügen Sie ein <tr>- und ein <td>-Element ein):
// 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>";
Definition und Verwendung
Die createTHead()-Methode erstellt ein leeres <thead>-Element und fügt es der Tabelle hinzu.
Hinweis: Wenn in der Tabelle bereits ein <thead>-Element vorhanden ist, gibt die createTHead()-Methode das vorhandene Element zurück und erstellt kein neues.
Hinweis: Das <thead>-Element muss ein oder mehrere <tr>-Tags enthalten.
Tipp: Um das Element <thead> aus einer Tabelle zu entfernen, verwenden Sie die Methode deleteTHead() .
Browser-Unterstützung
Method | |||||
---|---|---|---|---|---|
createTHead() | Yes | Yes | Yes | Yes | Yes |
Syntax
tableObject.createTHead()
Parameter
Keiner |
Technische Details
Rückgabewert: | Das neu erstellte (oder ein vorhandenes) <thead>-Element |
---|
Mehr Beispiele
Beispiel
Erstellen und löschen Sie ein <thead>-Element:
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();
}
Verwandte Seiten
HTML-Referenz: HTML-<thead>-Tag
❮ Tabellenobjekt