Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript relative jquery selector? Re: relative jquery selector?

#75752
joelbrock
Member

Since you know you need to go two levels up, you can use positional selectors

Code:
$(‘.someClass:eq(1)’) // selects the second element with a class name of someClass (yeah, it’s base 0)

For your example you can use (note: using parents() rather than parent()):

Code:
$(this).parents().eq(1).hide();

Which will find all parents of $(this), select the 2nd one, and hide it.