Show the number of cells in the first row:
The result of x will be:
More "Try it Yourself" examples below.
The cells collection returns a collection of all <td> or <th> elements in a table row.
Note: The elements in the collection are sorted as they appear in the source code.
Collection | |||||
---|---|---|---|---|---|
cells | Yes | Yes | Yes | Yes | Yes |
Property | Description |
---|---|
length | Returns the number of <td> and/or <th> elements in the collection. Note: This property is read-only |
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 |
DOM Version: | Core Level 2 Document Object |
---|---|
Return Value: | An HTMLCollection Object, representing all <td> and/or <th> elements in the <tr> element. The elements in the collection are sorted as they appear in the source code |
[index]
Alert the innerHTML of the first cell in the table's first row:
item(index)
Alert the innerHTML of the first cell in the table's first row:
namedItem(id)
Alert the innerHTML of the cell with id="myTd" in the table's first row:
Change the content of the first table cell: