views:

206

answers:

3

Is it possible in jQuery to daisy-chain selectors like so?

var sData = $('#myTableRow TD:nth-child(3):nth-child(2)').html();
+2  A: 

Yes, but that one in particular makes no sense, since the same <td> cannot be both the 3rd and the 2nd child of its parent. You can however combine multiple "pseudo-class" qualifiers that do make sense when applied together, like ":text:hidden" for example.

Pointy
+2  A: 

Yes, but you have to add spaces. '#myTable TD:nth-child(3) :nth-child(2)' means select the 2nd child of the TD which is the third in its parent.

Max Shawabkeh
+4  A: 

Perhaps you mean:

$('#myTableRow TD:nth-child(3) :nth-child(2)')

Which would be the 2nd child of the 3rd <TD>?

Dean Harding
This helped me select the second "A" anchor element of the third TD element. Exactly -- just what I needed. Saved me having to do this the hard way, and it's good to know I can daisy-chain in this fashion. And you are right -- that space before the final :nth-child() selector is very important.
Volomike