-1

So I have a few dynamic elements in a table and right now I am trying to add a class to the if it contains '2 minutes' problem is that if another container says '12 minutes' is adds the class to that as well. How can I just look for the 2 minutes and forget the 12 minutes?

$(".notice:contains('2 minutes')").addClass('highlight');
user1431083
  • 177
  • 1
  • 15

1 Answers1

2

Write your own filter function with strict comparison:

$('.notice').filter(function() {
    return $.text(this) === '2 minutes';
}).addClass('highlight');

If the required text is located within other text, you may use regular expression to test for validity, e.g. /\b2 minutes\b/.test($.text(this)).

VisioN
  • 143,310
  • 32
  • 282
  • 281