JSFiddle - React, Tailwind, and code Playground
by Curt
HTML
<div class="postbody">
<a class="lorem">test</a>
<div class="sub">
I'm only red when a.lorem exists in postbody!
</div>
</div>
<div class="postbody">
<div class="sub">
I'm only red when a.lorem exists in postbody!
</div>
</div>
CSS
.red
{
color:red;
}
JavaScript
$(function(){
$(".postbody .sub").each(function(){
var $sub = $(this);
var $postbody = $sub.parents(".postbody");
if ($postbody.find("a.lorem").length>0){
$sub.addClass("red");
}
});
});