Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 554
Rolando Avatar asked Apr 28 '12 03:04

Rolando


2 Answers

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)
like image 55
BoltClock Avatar answered Oct 07 '22 14:10

BoltClock


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

or

if ($("tr:has(td.specialclass)").length > 0) {
    // has specialclass
}
like image 20
dtbarne Avatar answered Oct 07 '22 16:10

dtbarne