jQuery: count number of rows in a table
Alternatively...
var rowCount = $('table#myTable tr:last').index() + 1;
jsFiddle DEMO
This will ensure that any nested table-rows are not also counted.
Well, I get the attr rows from the table and get the length for that collection:
$("#myTable").attr('rows').length;
I think that jQuery works less.
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!
If you use <tbody>
or <tfoot>
in your table, you'll have to use the following syntax or you'll get a incorrect value:
var rowCount = $('#myTable >tbody >tr').length;