JSFiddle - React, Tailwind, and code Playground
HTML
<div class="a e">ae
<div class="b d">bd
<div class="b c">bc</div>
</div>
</div>
JavaScript
jQuery.fn.anyBodyHome = function (selector) {
return this.is(selector) ? this
: this.find(selector).first()
}
// test
console.log($('.d').anyBodyHome('.c'))
console.log($('.d').anyBodyHome('.d'))
console.log($('.d').anyBodyHome('.e'))