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
var trimmedNotEmpty = function() {
var $this = $(this);
return !$this.is("p") || $.trim($this.text()) !== "";
};
$("div.wrapper")
.nextUntil(trimmedNotEmpty).remove().end()
.prevUntil(trimmedNotEmpty).remove();