TableRow - cellenverzameling
Voorbeeld
Toon het aantal cellen in de eerste rij:
var x = document.getElementById("myTable").rows[0].cells.length;
Het resultaat van x zal zijn:
2
Meer "Probeer het zelf" voorbeelden hieronder.
Definitie en gebruik
De cellenverzameling retourneert een verzameling van alle <td> of <th> elementen in een tabelrij.
Opmerking: de elementen in de collectie worden gesorteerd zoals ze in de broncode worden weergegeven.
Browserondersteuning
Collection | |||||
---|---|---|---|---|---|
cells | Yes | Yes | Yes | Yes | Yes |
Syntaxis
tableObject.cells
Eigenschappen
Property | Description |
---|---|
length | Returns the number of <td> and/or <th> elements in the collection. Note: This property is read-only |
Methoden:
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 |
Technische details
DOM-versie: | Kernniveau 2 documentobject |
---|---|
Winstwaarde: | Een HTMLCollection-object, dat alle <td>- en/of <th>-elementen in het <tr>-element vertegenwoordigt. De elementen in de collectie worden gesorteerd zoals ze in de broncode voorkomen |
Meer voorbeelden
Voorbeeld
[ index ]
Waarschuw de innerHTML van de eerste cel in de eerste rij van de tabel:
alert(document.getElementById("myTable").rows[0].cells[0].innerHTML);
Voorbeeld
artikel( index )
Waarschuw de innerHTML van de eerste cel in de eerste rij van de tabel:
alert(document.getElementById("myTable").rows[0].cells.item(0).innerHTML);
Voorbeeld
genoemdItem( id )
Waarschuw de innerHTML van de cel met id="myTd" in de eerste rij van de tabel:
alert(document.getElementById("myTable").rows[0].cells.namedItem("myTd").innerHTML);
Voorbeeld
Wijzig de inhoud van de eerste tabelcel:
var x = document.getElementById("myTable").rows[0].cells;
x[0].innerHTML = "NEW CONTENT";
❮ TabelRij-object