-2

I'm trying to add a class to my <li> whenever it contains "Tienes" (it means "you have" in Spanish"). I'm using this:

$('.pm-text:contains("Tienes")').parent().addClass('new-pm');

but with no results. Could anyone tell me what am I doing wrong?

This is the HTML I'm using:

<li id="menu-item-458" class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-458 erqf">
    <a href="/privmsg?folder=inbox" class="pm-text"> TEXT HERE </a>
</li>
Kara
  • 6,115
  • 16
  • 50
  • 57

2 Answers2

4

I suppose you are trying to access the elements even before it existed.

Put it inside DOM ready:

$(document).ready(function(){
  $('.pm-text:contains("Tienes")').parent().addClass('new-pm');
});
Amit Joki
  • 58,320
  • 7
  • 77
  • 95
1

Put it inside

$(document).ready(function(){
// here
}); 
joseramonc
  • 1,811
  • 2
  • 21
  • 40