Ronal
Ronal

Reputation: 2243

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

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

Upvotes: 7

Views: 17258

Answers (3)

jscharf
jscharf

Reputation: 5899

I think that

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

will work.

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

Upvotes: 11

Chetan S
Chetan S

Reputation: 23813

$("#someElement *:hidden").size()

Upvotes: 1

Keith
Keith

Reputation: 155792

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;

Upvotes: 19

Related Questions