user3707612
user3707612

Reputation: 11

Finding a text string with jQuery in table

I have this script:

$(document).ready(function(){
    var search = 'foo';
    $("table tr td").filter(function() {
        return $(this).text() == search;
    }).parent('tr').css('background-color','#f2dede');
});

What I want it to do is to color the background of the table whether the text is "foo" or "supfoo" or "foobar" or "foo foo". Anything with "foo" in it should be colored pink.

Not sure what to change! Please help...

Upvotes: 0

Views: 39

Answers (1)

oompahlumpa
oompahlumpa

Reputation: 503

Could you use :contains()?

$( "tr:contains('foo')" ).css( "background-color", "red" );

Upvotes: 2

Related Questions