tags:

views:

55

answers:

3

How to select next n hidden elements that have class "foo" using jQuery?

+2  A: 

Using nextAll() and filter():

$(this).nextAll().filter('.foo:hidden:lt('+n+')');

The :lt() selector selects the next n elements, the :hidden selector hidden inputs.

Boldewyn
Can you add `:hidden` to pick hidden inputs (as per OP's request)
alex
+1 Fastest fingers first.
amelvin
+2  A: 

Boldewyn's answer works, but filter is unnecessary. This also selects only hidden elements:

$(this).nextAll('.foo:hidden:lt('+n+')')
Tatu Ulmanen
+1 I missed the 'hidden' part of the question on first scan too.
amelvin
+1. Indeed, filter() is unnecessary.
Boldewyn
A: 
$(this).nextAll('.foo:hidden').filter(':lt('+n+')')
Mario Menger