Table rows collection
Table object
Definition and Usage
The rows collection returns an array of all rows (TableRow objects) in the table, which is an HTMLCollection.
This collection includes all rows defined in ,
, and .Syntax
tableObject.rows
property
| property | Description |
|---|---|
| length | Returns the number of in the collection |
Method
| Method | Description |
|---|---|
| [name_or_index] | An integer specifying the element retrieval position (starting from 0) td> |
| item(name_or_index) | Returns the element at the specified index in the collection |
| namedItem(name) | Returns the element with the specified name in the collection |
Browser support





All major browsers support the rows collection
Example
Example
Display the number of rows in the table:
<
!
DOCTYPE
html
<
html
<
head
<
meta
charset
=
"
utf-8
"
<
title
Runoob Tutorial(runoob.com)
title
<
script
function displayResult(){ alert(document.getElementById("myTable").rows.length); }
script
head
<
body
<
table
id
=
"
myTable
"
border
=
"
1
"
<
tr
<
td
cell 1
td
<
td
cell 2
td
tr
<
tr
<
td
cell 3
td
<
td
cell 4
td
tr
table
<
br
<
button
type
=
"
button
"
onclick
=
"
displayResult()
"
Display the number of rows in the table
button
body
html
Try it »
More examples
Pop up the content of the first row
Align the cell content in table rows
Vertical alignment of cell content in table rows
Align the content of an individual cell
Vertical alignment of cell content
Change the content of table cells
Table object