Question
$('table.listings td:contains("You")').each(function(){
$(this).children('td:nth-child(2)').addClass('highlighted');
});
I have multiple table.listings
on the page but the one that contains "You" is selected and I want to addClass highlighted
to the 2nd cell in each row, but the above code isn't working as I expected.
Solution
$('table.listings:contains("You") td:nth-child(2)').addClass("highlight");
OTHER TIPS
$('table.listings :contains("You")').each(function(){
$(this).children('td:nth-child(2)').addClass('highlighted');
});
Try this:
$('table.listings td:contains("You")').each(function(){
$("td:nth-child(2)", $(this).parent().parent().get(0)).addClass('highlighted');
});
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow