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

喜你入骨 提交于 2019-12-30 08:13:17

问题


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="specialclass someotherclass" (may potentially have other classes in addition to special class), how do I use jquery to check if a TR contains a TD of specialclass?


回答1:


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)



回答2:


if ($("tr").has("td.specialclass").length > 0) {
    // has specialclass
}

or

if ($("tr:has(td.specialclass)").length > 0) {
    // has specialclass
}


来源:https://stackoverflow.com/questions/10360450/how-to-check-if-a-tr-contains-a-td-with-a-specific-css-class-with-jquery

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!