$('table.listings td:contains("You")').each(function(){
$(this).children('td:nth-child(2)').addClass('highlighted');
});
ページに複数table.listings
ありますが、「あなた」を含むものが選択されており、各行の2番目のセルにClassを追加したいのですhighlighted
が、上記のコードが期待どおりに機能していません。
Try this:
$('table.listings td:contains("You")').each(function(){
$("td:nth-child(2)", $(this).parent().parent().get(0)).addClass('highlighted');
});
$('table.listings :contains("You")').each(function(){
$(this).children('td:nth-child(2)').addClass('highlighted');
});
$('table.listings:contains("You") td:nth-child(2)').addClass("highlight");