JSFiddle - React, Tailwind, and code Playground

HTML

<div id="root">
    Some text to be removed.
    <div>Some div not to be removed</div>
</div>

JavaScript

$('#root').contents().filter(function() {
    return this.nodeType == 3; // this is a text node
}).remove();