Search code examples
jquerycountrow

jQuery: count number of rows in a table


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.


Solution

  • 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!