Blog - jQuery

Count Number of Rows in a Table using Jquery

This is a quick snippet of how to effectively count the number of rows within a table. There are actually two approaches to take, depending on the markup of the table.

Using a HTML4 style table

$('#tableID tr').length;

Using a XHTML style table

$('#tableID >tbody >tr').length;

When testing this, you can place this code in an alert() or a console.debug() if your using Firebug.