JSFiddle - React, Tailwind, and code Playground

HTML

<table>
    <tbody>
      <tr>
     <td class="TargetRow">Not this one</td>
      </tr>
    </tbody>
    <tbody>
      <tr>
     <td class="TargetRow">This one</td>
      </tr>
    </tbody>
    <tbody> <tr><td>Other content</td></tr> </tbody>
    <tbody>
        <tr class="ContextRow"> ContextRow </tr>
    </tbody>
</table>

JavaScript

$(".ContextRow").closest("tbody").prevAll().find(".TargetRow").eq(0).css({color: "red"});