Koleksi sel TableRow
Contoh
Tunjukkan jumlah sel di baris pertama:
var x = document.getElementById("myTable").rows[0].cells.length;
Hasil dari x menjadi:
2
Lebih banyak contoh "Coba Sendiri" di bawah ini.
Definisi dan Penggunaan
Koleksi sel mengembalikan koleksi semua elemen <td> atau <th> dalam baris tabel.
Catatan: Elemen dalam koleksi diurutkan seperti yang muncul di kode sumber.
Dukungan Peramban
Collection | |||||
---|---|---|---|---|---|
cells | Yes | Yes | Yes | Yes | Yes |
Sintaksis
tableObject.cells
Properti
Property | Description |
---|---|
length | Returns the number of <td> and/or <th> elements in the collection. Note: This property is read-only |
Metode
Method | Description |
---|---|
[index] | Returns the <td> and/or <th> 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 <td> and/or <th> 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 <td> and/or <th> 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 <td> dan/atau <th> dalam elemen <tr>. Elemen-elemen dalam koleksi diurutkan seperti yang muncul dalam kode sumber |
Lebih Banyak Contoh
Contoh
[ indeks ]
Peringatkan innerHTML dari sel pertama di baris pertama tabel:
alert(document.getElementById("myTable").rows[0].cells[0].innerHTML);
Contoh
barang ( indeks )
Peringatkan innerHTML dari sel pertama di baris pertama tabel:
alert(document.getElementById("myTable").rows[0].cells.item(0).innerHTML);
Contoh
bernamaItem( id )
Beri tahu innerHTML sel dengan id="myTd" di baris pertama tabel:
alert(document.getElementById("myTable").rows[0].cells.namedItem("myTd").innerHTML);
Contoh
Ubah konten sel tabel pertama:
var x = document.getElementById("myTable").rows[0].cells;
x[0].innerHTML = "NEW CONTENT";
Objek TableRow