Reputation: 11830
I want to count the number of rows in my table that are not hidden. I can tell if a row is hidden by checking the style of the tr
attribute: <tr style="display: none; ">
. How do you calculate this using jquery?
Upvotes: 8
Views: 7491
Reputation: 4844
If you find out specific table do this
$("#tableid tr:visible").length
Upvotes: 1
Reputation: 13853
$('tr').filter(':visible').length
Tada! Note: Visible is a jQuery selector, so it is much faster to get your elements using a valid css selector then filtering them.
Upvotes: 3
Reputation: 34853
There is probably an easier way, but you could do this
var a = $('tr').length;
var b = $('tr[style="display:none;"]').length;
alert(a - b);
Example: http://jsfiddle.net/YV3cy/
Upvotes: 1
Reputation: 78731
The :visible selector will only select the visible items.
var count = $('#your-table tr:visible').length;
If you already have a variable that holds your rows, you can also use the filter
method.
var $rows = $('#your-table tr'),
visibleCount = $rows.filter(':visible').length;
Upvotes: 5
Reputation: 7802
you can use the :visible selector.
$('tr:visible').length;
here is a fiddle demonstrating this:
Upvotes: 15