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().each(function () {
    if(this.nodeType == 3 && $.trim(this.nodeValue) && $(this).parent(selector).length == 1)
    {
        $(this).replaceWith("changed text")
    }
});