Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery: How to count the number of elements which "display" isn't "none"?

Tags:

jquery

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.

like image 978
Misha Moroshko Avatar asked Mar 16 '11 12:03

Misha Moroshko


People also ask

How do I count the number of elements in jQuery?

To count all HTML elements, we use length property. The length property is used to count number of the elements of the jQuery object.

Is jQuery hide the same as display none?

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).

How do I find the number of elements in a div?

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.

What is the opposite of display none in JavaScript?

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.


1 Answers

Try this:

$('tr:not([style*="display: none"])').length

Example http://jsfiddle.net/infernalbadger/7LvD5/

like image 124
Richard Dalton Avatar answered Oct 16 '22 20:10

Richard Dalton