views:

965

answers:

3

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

Thanks in advance

+2  A: 

I think that

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

will work.

Updated: Added the '*'. Note that this will select the immediate children of #someElement.

jscharf
Nope, this will return 1, if #someElement is hidden, 0 otherwise.
Zed
You're right - the selector is missing a relation. Updated.
jscharf
Excellent answer, thank you!
Ronal
+10  A: 

Direct children of someElement that are hidden:

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

Any descendants of someElement that are hidden:

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

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

var ele = $('#someElement');

$(':hidden', ele).length;
Keith
+1  A: 
$("#someElement *:hidden").size()
Chetan Sastry