JSFiddle - React, Tailwind, and code Playground
HTML
<div>
somedirtytexthere.
<h1>header 1</h1>
<p>ok this text is cool</p>
This should not get removed
</div>
JavaScript
$("div")
.contents()
.filter(function () {
return this.nodeType === 3;
}).first().remove();