finding the closest previous sibling that contains .myClass

javascript, jquery

Solution

$currentTr.prevAll(':has(td.myClass)').first()

Problem

I have a bunch of `<tr>` some of them contain a `<td>` that has `class="myClass"` but some don't. So it looks like something like this. ``` <tr> <td class="myClass"></td> <td></td> </tr> <tr> <td></td> <td></td> </tr> ``` If I'm at a `<tr>`, how do I go up in rows until I hit the closest row that contains a `td.myClass`? Is there a clever way to do this? What I have now is a while loop that checks prev() and if it finds .myClass, it breaks.

Original source