I need to get all elements whose n-th parent (i.e. elem.parent().parent()…parent()) has a specific class. Is that possible?
For example:
<div class="success">
<div id="depth-1">
<div id="depth-2">
<div>Return me</div>
<div>Return me</div>
</div>
</div>
</div>
the command with parent depth of 3 and class “success” will return the "Return me" divs.
I’m not sure about n-deep, but this will get all divs whose great-grand-parent (n = 3) has the class
success.You could write a function to generate the selector. Something like: