JSFiddle - React, Tailwind, and code Playground

HTML

<div id="div_to_change">This is the text
    <br>to be changed
    <div id="div_that_shouldnt_change">text that should not change</div>
    <div id="div_that_shouldnt_change2">text that should not change</div>
</div>

JavaScript

var selector = '#div_to_change';
$(selector).contents().filter(function () {
    return (this.nodeType == 3 && $.trim(this.nodeValue))
    
}).replaceWith("changed text");