I am attempting to apply a class to an li
element based on its content. Currently, my code is applying the class to both the parent and child li
elements, but I only want it applied to the specific li
with certain content.
JS FIDDLE
<ul class="Team">
<li>Manager
<ul>
<li>Team Leader</li>
<li>Php Developer</li>
<li>Graphic Designer</li>
<li>Game Developer</li>
</ul>
</li>
<li>
Admin
<ul>
<li>Assistant Accountant</li>
</ul>
</li>
</ul>
I would like to add the class .trend
to the li
element that contains the text Game Developer
.
$('.Team li:contains(Game Developer)').addClass('trend');
However, this code applies the class to both the parent and child li
elements. Can anyone provide guidance on how to select the li
based on its content? Your help would be greatly appreciated.