JSFiddle - React, Tailwind, and code Playground

HTML

<h3 class="hideIfDivEmpty">Title 1 (hidden)</h3>
<div></div>

<h3 class="hideIfDivEmpty">Title 2 (title 1 is hidden)</h3>
<div>This div has content, so it will not be hidden.</div>

JavaScript

var divs = $(".hideIfDivEmpty");

divs.each(function () {
    var div = $(this);
    
    if (div.next().html() === "") {
        div.hide();
    }
});