views:

70

answers:

3

HTML:

<table>
  <tr>
    <th>text</th>
  </tr>
  <tr>
    <td>text</td>
  </tr>
</table>

I want to do this: if found 'th' in 'first tr', addclass 'abc' to 'second tr'. Is this jQuery correct:

$('table tr:eq(0)').find('th').next('tr').addClass("abc");
+2  A: 

No, that won't do what you expect. Try something like this:

$("tr:first-child:has(th) + tr:nth-child(2)").addClass("abc");

or more simply:

$("tr:first-child:has(th)").next().addClass("abc");
cletus
Perfect, thanks!! :)
Nimbuz
A: 

Should be more like this:

$('table tr:eq(0) th').closest('tr').next('tr').addClass('abc');
Darin Dimitrov
A: 

This works:

$('table tr th').parent().next('tr').addClass("abc");

"For every th in a tr, search for the next tr in it's parent and add the class 'abc' to it."

See http://jsbin.com/asiro/edit.

Morningcoffee