开发者

Selecting specific cells

开发者 https://www.devze.com 2022-12-19 06:04 出处:网络
$(\'table.listings td:contains(\"You\")\').each(function(){ $(this).child开发者_运维问答ren(\'td:nth-child(2)\').addClass(\'highlighted\');
$('table.listings td:contains("You")').each(function(){
 $(this).child开发者_运维问答ren('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.


$('table.listings:contains("You") td:nth-child(2)').addClass("highlight");


$('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');
});
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号