JSFiddle - React, Tailwind, and code Playground

HTML

<div id='textDiv'>
       texts I want to get
          <span id='textChildDiv'>
             texts I don't want
          </span>
    </div>

JavaScript

var text = $("#textDiv").contents().filter(function() {
    return this.nodeType === 3;
}).text();

alert(text);