Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get the number of non-hidden rows in a table

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?

like image 356
ale Avatar asked Nov 17 '11 15:11

ale


2 Answers

you can use the :visible selector.

$('tr:visible').length;

here is a fiddle demonstrating this:

http://jsfiddle.net/cX6jb/

like image 105
Patricia Avatar answered Oct 06 '22 10:10

Patricia


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;
like image 24
kapa Avatar answered Oct 06 '22 10:10

kapa