Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery - Get table row count with a certain class

I know I can get the number of rows in an HTML table with the following jQuery:

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

However, how can I get the number of rows that have a given class (e.g., <tr class="MyClass>). How can I count the number of rows in a table with a class of "MyClass"?

like image 842
Randy Minder Avatar asked Apr 15 '14 22:04

Randy Minder


1 Answers

Simply add the class to the selector

var rows= $('#myTable tbody tr.MyClass').length;
like image 182
Adam Avatar answered Oct 04 '22 19:10

Adam