JSFiddle - React, Tailwind, and code Playground
by john_s
HTML
<table>
<tr>
<td>
<div>some content</div>
<select class="this" id="thisId">
<option>1</option>
<option>2</option>
</select>
</td>
</tr>
<tr id="second">
<td>
<div>some content</div>
<select class="that" id="thatId">
<option>1</option>
<option>2</option>
</select>
</td>
</tr>
</table>
JavaScript
$.fn.nextAfter = function(selector) {
var $result = $();
this.each(function() {
var $element = $(this);
var $match = $element.find(selector);
if ($match.length > 0) {
$result = $result.add($match.eq(0));
} else {
var $next = $element.next();
while ($next.length == 0) {
$element = $element.parent();
if ($element.length == 0) {
break;
}
$next = $element.next();
}
if ($next.length > 0) {
$result = $result.add($next.nextAfter(selector));
}
}
});
return $result;
}
var $this = $('.this');
console.log($this.nextAfter('.that').attr('id'));