JSFiddle - React, Tailwind, and code Playground

HTML

<div>
<p>this is a paragraph and <a>this is not</a>.</p>
Here we have a div.
</div>

JavaScript

var myArray = $('*:contains("this")','body').filter(function(){
    if($(this).contents().filter(function(){
        return(this.nodeType == 3);
    }).text().indexOf('this')===-1){
        return false;
    }
    return true;
});


$.each(myArray,function(){
   console.log(this.nodeName); 
});