Home › Forums › JavaScript › relative jquery selector? › Re: relative jquery selector?
May 14, 2010 at 8:31 pm
#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.