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?
you can use the :visible selector.
$('tr:visible').length;
here is a fiddle demonstrating this:
http://jsfiddle.net/cX6jb/
The :visible selector will only select the visible items.
var count = $('#your-table tr:visible').length;
jsFiddle Demo
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;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With