Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
168
rated 0 times [  173] [ 5]  / answers: 1 / hits: 42698  / 10 Years ago, tue, april 15, 2014, 12:00:00

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?


More From » jquery

 Answers
16

Simply add the class to the selector



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

[#71447] Monday, April 14, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
sonja

Total Points: 541
Total Questions: 113
Total Answers: 114

Location: Anguilla
Member since Sun, Jan 29, 2023
1 Year ago
sonja questions
Mon, Nov 30, 20, 00:00, 4 Years ago
Sun, Oct 11, 20, 00:00, 4 Years ago
Thu, May 21, 20, 00:00, 4 Years ago
Sun, Nov 10, 19, 00:00, 5 Years ago
Mon, Aug 26, 19, 00:00, 5 Years ago
;