Kolekce buněk TableRow
Příklad
Ukažte počet buněk v prvním řádku:
var x = document.getElementById("myTable").rows[0].cells.length;
Výsledkem x bude:
2
Další příklady „Vyzkoušejte si to sami“ níže.
Definice a použití
Kolekce buněk vrátí kolekci všech prvků <td> nebo <th> v řádku tabulky.
Poznámka: Prvky v kolekci jsou seřazeny tak, jak se objevují ve zdrojovém kódu.
Podpora prohlížeče
Collection | |||||
---|---|---|---|---|---|
cells | Yes | Yes | Yes | Yes | Yes |
Syntax
tableObject.cells
Vlastnosti
Property | Description |
---|---|
length | Returns the number of <td> and/or <th> elements in the collection. Note: This property is read-only |
Metody
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 |
Technické údaje
Verze DOM: | Základní objekt dokumentu úrovně 2 |
---|---|
Návratová hodnota: | Objekt HTMLCollection, který představuje všechny prvky <td> a/nebo <th> v prvku <tr>. Prvky v kolekci jsou seřazeny tak, jak se objevují ve zdrojovém kódu |
Další příklady
Příklad
[ index ]
Upozornit na innerHTML první buňky v prvním řádku tabulky:
alert(document.getElementById("myTable").rows[0].cells[0].innerHTML);
Příklad
položka ( index )
Upozornit na innerHTML první buňky v prvním řádku tabulky:
alert(document.getElementById("myTable").rows[0].cells.item(0).innerHTML);
Příklad
NameItem( id )
Upozorněte vnitřní HTML buňky pomocí id="myTd" v prvním řádku tabulky:
alert(document.getElementById("myTable").rows[0].cells.namedItem("myTd").innerHTML);
Příklad
Změňte obsah první buňky tabulky:
var x = document.getElementById("myTable").rows[0].cells;
x[0].innerHTML = "NEW CONTENT";
❮ Objekt TableRow