JSFiddle - React, Tailwind, and code Playground
HTML
<div id="foo">
first
<div id="bar1">
jumps over a lazy dog!
</div>
second
<div id="bar2">
another jumps over a lazy dog!
</div>
third
</div>
JavaScript
console.log($("#foo").contents());
$("#foo").contents().filter(function () {
return this.nodeType === 3;
}).remove();