views:

58

answers:

2

Hey all,

I've got a bit of a jQuery problem. I've got multiple tables on a page that all have the same class but no ID. I'd like to be able to be able to get the first row from all of the tables back. Is there an easy way to do this?

This is what I've got so far:

$(.t13Standard tr:first')

But that only selects the first row from the first table. Any way to get the first row from all the tables?

Thanks, Matt

+1  A: 

I would have thought you could do something like

$('table.someClass tr:first').each(
function()
{
// Do something here
});
Michael Ciba
This is wrong. It is the equivalent of the OP's code.
Doug Neiner
Not exactly. The .each will probably make a difference, though I didn't choose to go that way.
Sonny Boy
+1  A: 

You need to use nth-child() or first-child():

$('.t13Standard tr:first-child')

or

$('.t13Standard tr:nth-child(1)')

The pseudo selectors :first, :eq(), :gt() etc are performed on the result set not in relation to other elements.

The selectors :first-child, :last-child, :nth-child() are performed in relation to the elements.

Doug Neiner
Thank you very much!
Sonny Boy