JSFiddle - React, Tailwind, and code Playground

by forgetcolor

HTML

<div id='tst1'>
  <div id='tst2'>tst2</div>
  <div id='tst3'>tst3</div>
  this is the text i want
</div>

JavaScript

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

};

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

};

console.log(($('#tst1').justtext()));
console.log(($('#tst1').justtextinner()));