jQuery - find table row containing table cell containing specific text

前端 未结 5 1731
孤街浪徒
孤街浪徒 2020-12-07 22:21

I need to get a tr element which contains a td element which contains specific text. The td will contain that text and only that text

5条回答
  •  不知归路
    2020-12-07 22:39

    $(function(){
        var search = 'foo';
        $("table tr td").filter(function() {
            return $(this).text() == search;
        }).parent('tr').css('color','red');
    });
    

    Will turn the text red for rows which have a cell whose text is 'foo'.

提交回复
热议问题