I use show()
and hide()
to show and hide rows in a table.
How could I count the number of non-hidden rows (more accurately, rows with display
!= none
) ?
Note that:
$('tr:visible').length
won't work because if the table itself has display=none
, the result will always be 0.
To count all HTML elements, we use length property. The length property is used to count number of the elements of the jQuery object.
jQuery hide() Method The hide() method hides the selected elements. Tip: This is similar to the CSS property display:none. Note: Hidden elements will not be displayed at all (no longer affects the layout of the page).
To count all elements inside a div elements, we use find() method and length property. The find() method is used to find all the descendant elements of the selected element.
The Best Answer is display: none doesn't have a literal opposite like visibility:hidden does. The visibility property decides whether an element is visible or not. It therefore has two states ( visible and hidden ), which are opposite to each other.
Try this:
$('tr:not([style*="display: none"])').length
Example http://jsfiddle.net/infernalbadger/7LvD5/
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