TableRow hücreleri Koleksiyonu
Örnek
İlk satırdaki hücre sayısını göster:
var x = document.getElementById("myTable").rows[0].cells.length;
x'in sonucu şöyle olacaktır:
2
Aşağıda daha fazla "Kendiniz Deneyin" örnekleri.
Tanım ve Kullanım
Hücre koleksiyonu, bir tablo satırındaki tüm <td> veya <th> öğelerinin bir koleksiyonunu döndürür.
Not: Koleksiyondaki öğeler, kaynak kodda göründükleri gibi sıralanır.
Tarayıcı Desteği
Collection | |||||
---|---|---|---|---|---|
cells | Yes | Yes | Yes | Yes | Yes |
Sözdizimi
tableObject.cells
Özellikler
Property | Description |
---|---|
length | Returns the number of <td> and/or <th> elements in the collection. Note: This property is read-only |
yöntemler
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 |
Teknik detaylar
DOM Sürümü: | Çekirdek Düzey 2 Belge Nesnesi |
---|---|
Geri dönüş değeri: | <tr> öğesindeki tüm <td> ve/veya <th> öğelerini temsil eden bir HTMLCollection Nesnesi. Koleksiyondaki öğeler, kaynak kodda göründükleri gibi sıralanır. |
Daha fazla örnek
Örnek
[ dizin ]
Tablonun ilk satırındaki ilk hücrenin innerHTML'sini uyarın:
alert(document.getElementById("myTable").rows[0].cells[0].innerHTML);
Örnek
öğe ( dizin )
Tablonun ilk satırındaki ilk hücrenin innerHTML'sini uyarın:
alert(document.getElementById("myTable").rows[0].cells.item(0).innerHTML);
Örnek
nameItem( id )
Tablonun ilk satırında id="myTd" ile hücrenin innerHTML'sini uyarın:
alert(document.getElementById("myTable").rows[0].cells.namedItem("myTd").innerHTML);
Örnek
İlk tablo hücresinin içeriğini değiştirin:
var x = document.getElementById("myTable").rows[0].cells;
x[0].innerHTML = "NEW CONTENT";
❮ TableRow Nesnesi