14

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?

2
  • if($('tr').find('td.specialclass').length>0 || $('tr').find('td[class*="specialclass"]').length>0) ... that's your check and direct query selection goes the same way. What you're looking for? Commented Apr 28, 2012 at 4:03
  • I know we get embarrassed sometimes about answering questions that SEEM easy to us, but let's keep the comment area for comments and post answers as answers! Commented Apr 28, 2012 at 4:06

2 Answers 2

33

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)
Sign up to request clarification or add additional context in comments.

1 Comment

I guess you beat me by like 30 seconds. :)
8
if ($("tr").has("td.specialclass").length > 0) {
    // has specialclass
}

or

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.