JSFiddle - React, Tailwind, and code Playground

HTML

<p></p>
<p>not empty</p>
<p>not empty</p>
<p></p>
<div class="wrapper">
    // more content inside
</div>
<p></p>
<p></p>
<a></a>
<p>not empty</p>

JavaScript

$("div.wrapper")
    .nextUntil(":not(:empty)").remove().end()
    .prevUntil(":not(:empty)").remove();