views:

1596

answers:

2

I'm trying to move X number of rows down in a table using jQuery...

I can do the following and it works....

/* Now let's move next 3 times to arrive at the foo account */
for (var rowCount = 1; rowCount <=3; rowCount++) {
    foobarRow = $(foobarRow).next('tr');
}

I realize I could go

    foobarRow = $(foobarRow).next('tr');
    foobarRow = $(foobarRow).next('tr');
    foobarRow = $(foobarRow).next('tr');

also...

but I'm wondering if there's not a more jQueryish way to accomplish the same thing?

like, I don't know, but(totally made up jQuery syntax follows)...

foobarRow = $(foobarRow).next('tr').number(3);
+5  A: 

You can match elements by their index :eq(index).

$("tr:eq(2)") selects the third TR. Note, this is a zero-based index.

Jonathan Sampson
+1  A: 

This should do it:-

foobarRow = $(foobarRow).siblings().get(2);
AnthonyWJones
Anthony,Thanks for your answer...This gets me the row I want...lineItemsRow = $(lineItemsRow).parent().children("tr").eq($(lineItemsRow)[0].rowIndex + 3)The two answers are so close(and correct and a big help) that I'm gonna take Jonathan's answer just because he was first...Thanks again, Greg
w4ik