JSFiddle - React, Tailwind, and code Playground

HTML

<div id="mydiv">
    some text here 
    <div id="inner div">
         text for inner div
    </div>
</div>

JavaScript

jQuery.fn.justtext = function() {
  
    return $(this).clone()
            .children()
            .remove()
            .end()
            .text();

};

alert($('#mydiv').justtext());