I want to select elements that contain text regardless of their type. I don't want to select their ascendants. I tried this $(":contains('Twilight')").css('border-left', '1px solid purple');
but that selects elements with the text and it's ancestor elements up the dom tree.
Below is some HTML for example. I want to select the ones marked with <!-- THIS -->
, nothing else. How do I do that?
<div> <!-- no -->
<h1>Magical ponies</h1> <!-- no -->
<ul> <!-- no -->
<li>Fluttershy</li> <!-- no -->
<li>Pinkie pie</li> <!-- no -->
<li>Twilight sparkle</li> <!-- THIS -->
<li>Hurdurrdurr</li> <!-- no -->
</ul>
</div>
<div>Twilight is a movie too</div> <!-- THIS -->
<p>Hurr <!-- no -->
<span>Twilight ZONE</span> <!-- THIS -->
Durr</p>
Here's a jsfiddle to play with: http://jsfiddle.net/34C7Z/ - I specifically want the solution to be jquery and not native JS.