Reputation: 35
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
Reputation: 3752
Code
$('#transport td').filter(
function(t){
if($(this).text() =="TPS999") {
$(this).closest('tr').css('background-color','Red');
// alert("i am in");
return;
}
});
Upvotes: 1
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
Reputation: 18861
Like so:
var $cell = $('#transport td').filter(function() {
return $(this).text() == 'TPS999';
});
$cell.closest('tr').addClass("marked")
Upvotes: 0
Reputation: 28513
Try this :
$('#transport td').filter(function() {
return $(this).text() == 'TPS999';
}).closest('tr').addClass("marked");
Upvotes: 1