JSFiddle - React, Tailwind, and code Playground
HTML
<div id="div-1">
<div id="div-2">
</div>
<div id="div-3">
<div id="div-4">
</div>
<div id="div-5">
</div>
</div>
</div>
JavaScript
if ($("#div-5").parents("#div-1")) alert("It's there");
else alert("It's not there");