Koleksi Tabel tBody
Contoh
Cari tahu berapa banyak elemen <tbody> yang ada dalam sebuah tabel:
var x = document.getElementById("myTable").tBodies.length;
Hasil dari x menjadi:
2
Lebih banyak contoh "Coba Sendiri" di bawah ini.
Definisi dan Penggunaan
Koleksi tBodies mengembalikan koleksi semua elemen <tbody> dalam sebuah tabel.
Catatan: Elemen dalam koleksi diurutkan seperti yang muncul di kode sumber.
Dukungan Peramban
Collection | |||||
---|---|---|---|---|---|
tBodies | Yes | Yes | Yes | Yes | Yes |
Sintaksis
tableObject.tBodies
Properti
Property | Description |
---|---|
length | Returns the number of <tbody> elements in the collection. Note: This property is read-only |
Metode
Method | Description |
---|---|
[index] | Returns the <tbody> element from the collection with the specified index (starts at 0). Note: Returns null if the index number is out of range |
item(index) | Returns the <tbody> element from the collection with the specified index (starts at 0). Note: Returns null if the index number is out of range |
namedItem(id) | Returns the <tbody> element from the collection with the specified id. Note: Returns null if the id does not exist |
Detail Teknis
Versi DOM: | Objek Dokumen Tingkat 2 Inti |
---|---|
Nilai Kembali: | Objek HTMLCollection, mewakili semua elemen <tbody> dalam elemen <table>. Elemen-elemen dalam koleksi diurutkan seperti yang muncul dalam kode sumber |
Lebih Banyak Contoh
Contoh
[ indeks ]
Beri tahu innerHTML dari elemen <tbody> pertama (indeks 0) dalam tabel:
alert(document.getElementById("myTable").tBodies[0].innerHTML;
Contoh
barang ( indeks )
Beri tahu innerHTML dari elemen <tbody> pertama (indeks 0) dalam tabel:
alert(document.getElementById("myTable").tBodies.item(0).innerHTML);
Contoh
bernamaItem( id )
Beri tahu innerHTML dari elemen <tbody> dengan id="myTBody" di tabel:
alert(document.getElementById("myTable").tBodies.namedItem("myTBody").innerHTML);
Halaman Terkait
Referensi HTML: tag HTML <tbody>
Objek Tabel