JSFiddle - React, Tailwind, and code Playground
HTML
<table id="tab">
<thead>
<tr id="tabhead">
<th>Amount</th>
<th>Update</th>
<th>Delete</th>
</tr>
</thead>
<tbody>
<tr id="tabbody">
<td>150.0</td>
<td align="center">
<a href='#' class='updatelink'>u</a>
</td>
<td><a href='#'>x</a></td>
</tr>
</tbody>
</table>
<ul id="result"></ul>
JavaScript
var source = $("a.updatelink"),
parents = source.parents(),
filtered = {
// ???
byPosRel: parents.filter("table:first tr:first"),
// the closest ancestor tr,
// but only if it is a descendant of the closest ancestor table
"right-preferred": parents.filter("tr:first").filter(function() {
return parents.filter("table:first").has( this );
}),
// the first tr descendant of the closest ancestor table,
// but only if it contains the target
"left-preferred": parents.filter("table:first").find("tr:first").has( source )
};
jQuery.each( filtered, function( label, collection ) {
$("#result").append( "<li>" + label + "=" + ( collection.attr("id") || "nothing" ) + "</li>" );
});