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

$('#textDiv').click(function(){
   
    alert($(this).contents().filter(function() {
        return this.nodeType === 3;
      }).text())
});