Tabel createTHead() Metode
Contoh
Buat elemen <thead> (dan masukkan elemen <tr> dan <td> ke dalamnya):
// 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>";
Definisi dan Penggunaan
Metode createTHead() membuat elemen <thead> kosong dan menambahkannya ke tabel.
Catatan: Jika elemen <thead> sudah ada di tabel, metode createTHead() mengembalikan yang sudah ada, dan tidak membuat yang baru.
Catatan: Elemen <thead> harus memiliki satu atau lebih tag <tr> di dalamnya.
Tip: Untuk menghapus elemen <thead> dari tabel, gunakan metode deleteTHead() .
Dukungan Peramban
Method | |||||
---|---|---|---|---|---|
createTHead() | Yes | Yes | Yes | Yes | Yes |
Sintaksis
tableObject.createTHead()
Parameter
Tidak ada |
Detail Teknis
Nilai Kembali: | Elemen <thead> yang baru dibuat (atau yang sudah ada) |
---|
Lebih Banyak Contoh
Contoh
Buat dan hapus elemen <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();
}
Halaman Terkait
Referensi HTML: HTML <thead> tag
Objek Tabel