jQuery: count number of rows in a table

danjan picture danjan · Jul 19, 2009 · Viewed 719.9k times · Source

How do I count the number of tr elements within a table using jQuery?

I know there is a similar question, but I just want the total rows.

Answer

tvanfosson picture tvanfosson · Jul 19, 2009

Use a selector that will select all the rows and take the length.

var rowCount = $('#myTable tr').length;

Note: this approach also counts all trs of every nested table!