For the original question: If you are out of range, you can do this:
$(".theSpanClass").parents("table:last")
Here, .parents() is used to get all the <table> ancestors, then selects :last , which it finds, since they are ordered going up the DOM.
Updated for new question:. Since the question has been updated, these are 2 levels up, which you will find with :eq() :
$(".theSpanClass").parents("table:eq(1)")
source share