SpiDey
SpiDey

Reputation: 71

Hide TR when TR contains a keyword

I want to hide a tr when one of it's td contains a part of the keyword "Aufruestung".

E.g. one td has the text "APL Aufruestung 10", I want to find it and hide the complete tr - but just the first tr, not all the parents. My first try doesn't work at all, I think i have to do something with RegEx to find all the tr's with "Aufruestung"? I'm not sure and a newbie to jQuery...

jQuery('td:contains("Aufruestung"))').closest('tr').hide()

Upvotes: 1

Views: 886

Answers (2)

Vaibs_Cool
Vaibs_Cool

Reputation: 6156

Try this

$("td").each(function() {
var str = 'Aufruestung';
var txt = $(this).html();  
   alert(txt); // to cross verify
    if (/Aufruestung/i.test(txt)){
alert('String Contains Word');

} else {
alert('String Does not contains word');

}  
});

Live Demo

Upvotes: 1

Milind Anantwar
Milind Anantwar

Reputation: 82231

You have typo in your code. extra ) is added in it. also you can check for contains is tr rather than in tds:

jQuery('tr:contains(Aufruestung)').hide()

Upvotes: 0

Related Questions