jQuery - find table row containing table cell containing specific text

前端 未结 5 1729
孤街浪徒
孤街浪徒 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:46

    I know this is an old post but I thought I could share an alternative [not as robust, but simpler] approach to searching for a string in a table.

    $("tr:contains(needle)"); //where needle is the text you are searching for.

    For example, if you are searching for the text 'box', that would be:

    $("tr:contains('box')");
    

    This would return all the elements with this text. Additional criteria could be used to narrow it down if it returns multiple elements

提交回复
热议问题