JSFiddle - React, Tailwind, and code Playground
HTML
<div> <!-- NOT THIS -->
<h1>Magical ponies</h1> <!-- NOT THIS -->
<ul> <!-- NOT THIS -->
<li>Fluttershy</li> <!-- NOT THIS -->
<li>Pinkie pie</li> <!-- NOT THIS -->
<li>Twilight sparkle</li> <!-- THIS -->
<li>Hurdurrdurr</li> <!-- NOT THIS -->
</ul>
</div>
<div>Twilight is a movie too <span>Twilight</span></div> <!-- THIS -->
<p>Hurr durr <!-- NOT THIS -->
<span>Twilight <span>ZONE</span></span> <!-- THIS -->
Durr</p>
JavaScript
var v = $('*').contents().filter(function(){
return this.data && this.data.match(/Twilight/g);
}).parent();
v.children().each(function(){
v = v.has(this)?v.not(this):v;
});
v.css('border-left', '1px solid purple');