JSFiddle - React, Tailwind, and code Playground

HTML

<div id='textDiv'>        
    texts I want to get           
    <span id='textChildDiv'>             
        texts I don't want           
    </span>
    Can be at the bottom too.
</div>

JavaScript

$(function () {
    var result = '';
    $('#textDiv').contents().each(function () {
        if (this.nodeType == 3 && $.trim($(this).text()).length > 0) {
            result += this.nodeValue;
        }
    });
    alert(result);
});