user964960
user964960

Reputation: 35

jquery find table cell with value and highlight tr

What i have done:

$('#transport td').filter(function() {
    return $(this).text() == 'TPS999';
}).addClass("marked");

now it highlights

how can i highlight that row where i found text (tr)?

Upvotes: 1

Views: 1169

Answers (4)

Anil
Anil

Reputation: 3752

Jsfiddle

Code

$('#transport td').filter(
function(t){
     if($(this).text() =="TPS999") {
        $(this).closest('tr').css('background-color','Red');
        // alert("i am in");
        return;
    }

});

Upvotes: 1

Adil
Adil

Reputation: 148110

Use closest('tr') to get the parent row and return row instead of td.

$('#transport td').filter(function() {
    if($(this).text() == 'TPS999')
       return $(this).closest('tr');
}).addClass("marked");

OR, you can use :contains to select all elements that contain the specified text and use closest('tr') to get the parent td and add class to it.

$('#transport td:contains("TPS999")').closest('tr').addClass("marked");

Upvotes: 0

MightyPork
MightyPork

Reputation: 18861

Like so:

var $cell = $('#transport td').filter(function() {
    return $(this).text() == 'TPS999';
});

$cell.closest('tr').addClass("marked")

Upvotes: 0

Bhushan Kawadkar
Bhushan Kawadkar

Reputation: 28513

Try this :

$('#transport td').filter(function() {
    return $(this).text() == 'TPS999';
}).closest('tr').addClass("marked");

Upvotes: 1

Related Questions