Table rowsCollection

Table 对象参考手册Table Object

Definition and Usage

The rows collection returns an array of all rows (TableRow objects) in a table, i.e., an HTMLCollection.

This collection includes all rows defined in <thead>, <tfoot>, and <tbody>.

Syntax

tableObject.rows

Properties

Property Description
length Returns the number of <tr> elements in the collection.

Methods

Method Description
[name_or_index] 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 in the collection.


Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support the rows collection.


Example

Example

Display the number of rows in a table:

<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>Example (example.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()">Show the number of rows in the table</button> </body> </html>

Try it Yourself »


实例

More Examples


Table 对象参考手册Table Object Other Extensions