Latest web development tutorials

HTML DOM tr cells collection

tr Object Reference tr objects

Examples

Display the cell number of the first line:

var x = document.getElementById ( "myTable" ) .rows [0] .cells.length;

x The output is:

2
try it"

Definition and Usage

Returns a collection of cells in the table row number all the <td> or <th> element.

Note: The order of the elements in the collection of the order in the source code is the same.


Browser Support

set
cells Yes Yes Yes Yes Yes

grammar

tableObject.cells

Attributes

Attributes description
length Returns collection <td> number or <th> element.

Note: This property is read-only.

method

method description
[Name_or_index] An integer that specifies the element to retrieve the location (starting from 0)
item(name_or_index) Returns the collection at the specified index element
namedItem(name) Returns the name of the index in the collection specified element index

Technical Description

DOM version: Core Level 2 Document Object
return value: HTMLCollection object that represents the <tr> all <td> or <th> element. The order of elements in the collection of the order in the source code is the same.

More examples

Examples

[Index]

Pop contents of the first row of a cell:

alert (document.getElementById ( "myTable") .rows [0] .cells [0] .innerHTML);

try it"

Examples

item (index)

Pop contents of the first row of a cell:

alert (document.getElementById ( "myTable") .rows [0] .cells.item (0) .innerHTML);

try it"

Examples

namedItem (id)

Pop contents of the first row id = "myTd" cell:

alert (document.getElementById ( "myTable") .rows [0] .cells.namedItem ( "myTd") .innerHTML);

try it"

Examples

Modify the contents of the first cell:

var x = document.getElementById ( "myTable" ) .rows [0] .cells;
x [0] .innerHTML = "NEW CONTENT";

try it"

tr Object Reference tr objects