I want to count the number of rows in my table that are not hidden. I can tell if the string is hidden by checking the attribute style tr : <tr style="display: none; "> . How do you calculate this using jquery?
tr
<tr style="display: none; ">
you can use the: visible selector.
$('tr:visible').length;
here is a fiddle demonstrating this:
http://jsfiddle.net/cX6jb/
: The view selector will only display visible elements.
var count = $('#your-table tr:visible').length;
jsFiddle Demo
If you already have a variable containing your strings, you can also use the filter method.
filter
var $rows = $('#your-table tr'), visibleCount = $rows.filter(':visible').length;
$('tr').filter(':visible').length
TA-dah! Note. Visible is a jQuery selector, so itβs much faster to get your elements using a valid css selector, then filter them out.
: visible
There may be an easier way, but you can do it
var a = $('tr').length; var b = $('tr[style="display:none;"]').length; alert(a - b);
Example: http://jsfiddle.net/YV3cy/
If you recognize a specific table, do it
$("#tableid tr:visible").length