Coll Tr Cells
# HTML DOM tr cells Collection
[ tr Object](#)
### Example
Display the number of cells in the first row:
var x = document.getElementById("myTable").rows.cells.length;
_x_ outputs:
2
[Try it Β»](#)
* * *
## Definition and Usage
The cells collection returns the number of or elements in a table row.
**Note:** The elements in the collection are in the same order as they are in the source code.
* * *
## Browser Support
| Collection | | | | | |
| --- | --- | --- | --- | --- | --- |
| cells | Yes | Yes | Yes | Yes | Yes |
* * *
## Syntax
tableObject.cells
* * *
## Properties
| Property | Description |
| --- | --- |
| length | Returns the number of or elements in the collection. **Note:** This property is read-only. |
* * *
## Methods
| Method | Description |
| :--- | :--- |
| | An integer specifying the position of the element to retrieve (starting from 0) |
| item(_name_or_index_) | Returns the element at the specified index in the collection |
| namedItem(_name_) | Returns the element with the specified name or id in the collection |
* * *
## Technical Details
| DOM Version: | Core Level 2 Document Object |
| --- |
| Return Value: | An HTMLCollection object, representing all or elements within a . The elements in the collection are in the same order as they are in the source code. |
* * *
## More Examples
### Example
Alert the content of the first cell in the first row:
alert(document.getElementById("myTable").rows.cells.innerHTML);
[Try it Β»](#)
### Example
item(_index_)
Alert the content of the first cell in the first row:
alert(document.getElementById("myTable").rows.cells.item(0).innerHTML);
[Try it Β»](#)
### Example
namedItem(_id_)
Alert the content of the cell with id="myTd" in the first row:
alert(document.getElementById("myTable").rows.cells.namedItem("myTd").innerHTML);
[Try it Β»](#)
### Example
Modify the content of the first cell:
var x = document.getElementById("myTable").rows.cells;
x.innerHTML = "NEW CONTENT";
[Try it Β»](#)
* * tr Object](#)
YouTip