Lets say I have the following:
<table><tr><td>
<table> <!-- I want a reference to this table -->
<tr>
<td>
<table>
<tr><td><span class="theSpanClass"></span></td></tr>
</table>
</td>
</tr>
</table>
</td></tr></table>
Using jQuery, I’d like to be able to reference the 2nd table starting from the span towards the body.
Thanks
For original question: If you’re coming from the span, then you can do this:
This uses
.parents()to get all ancestors that are<table>, then selects the:lastone it finds, since they’re ordered going up the DOM.Updated for new question: Since the question’s been updated, that’s 2 levels up, which you would find using
:eq()like this: