$('table.listings td:contains("You")').each(function(){
$(this).children('td:nth-child(2)').addClass('highlighted');
});
我table.listings
在页面上有多个,但包含“你”的那个被选中,我想将类添加highlighted
到每一行的第二个单元格,但上面的代码没有按我预期的那样工作。
试试这个:
$('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");