How can I count the number of elements in a div that are hidden?

How to count the number of elements in a div that are hidden using jQuery?

+4
source share
3 answers

I think that

$("#someElement > *").filter(":hidden").size(); 

will work.

Updated: Added '*'. Note that this will result in a selection of the immediate children of #someElement .

+7
source

The direct children of some element that are hidden:

 $('#someElement > :hidden').length; 

Any descendants of some element that are hidden:

 $('#someElement :hidden').length; 

If you already have a jQuery object, you can use it as a context:

 var ele = $('#someElement'); $(':hidden', ele).length; 
+18
source
 $("#someElement *:hidden").size() 
+1
source

All Articles