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

function findElmsWithWord(word, elm, found){
    if (elm.nodeType === 3 && elm.data.indexOf(word) !== -1)
        found.push(elm.parentNode);
    else
        for (var i = 0; i < elm.childNodes.length; i++)
            findElmsWithWord(word, elm.childNodes[i], found);
}

var elms = [];
findElmsWithWord('this', document.body, elms);
console.log(elms);