How to check if a TR contains a TD with a specific CSS class with jquery?

前端 未结 2 458
一生所求
一生所求 2021-01-11 16:09

I know you can use .find to find td:contains(\'text\'), but if I have a tr with say, 3 td\'s, and one of the td\'s might have class=

相关标签:
2条回答
  • 2021-01-11 16:25
    if ($("tr").has("td.specialclass").length > 0) {
        // has specialclass
    }
    

    or

    if ($("tr:has(td.specialclass)").length > 0) {
        // has specialclass
    }
    
    0 讨论(0)
  • 2021-01-11 16:32

    To select any tr that has a td.specialclass:

    $('tr:has(td.specialclass)')
    

    Or if you have a tr (represented by this) and you simply want to check if it has such a td:

    if ($(this).find('td.specialclass').length)
    
    0 讨论(0)
提交回复
热议问题