Yetimwork Beyene
Yetimwork Beyene

Reputation: 249

How to find 2nd and 3rd td's within a table row after finding the first td using jquery?

This works:

       $("#topTable tr[data-mainRow]:even").find("td:first").addClass("zibraBackground");

However, how can I identify the additional td's within this row, example, td 2 and td 3 using the method above...

Upvotes: 0

Views: 403

Answers (2)

Piotr Miś
Piotr Miś

Reputation: 981

You can also use CSS-like :nth-child(k). Example:

var tr = $("#topTable tr[data-mainRow]:even");
tr.find("td:nth-child(1)").doSomething();
tr.find("td:nth-child(2)").doSomething();
tr.find("td:nth-child(3)").doSomething();

The indexes start at 1 not 0.

Upvotes: 0

Streamside
Streamside

Reputation: 332

What you are looking is the pseudo selector :eq(n) where n is the index of the element you want to get.

http://api.jquery.com/eq-selector/

Upvotes: 1

Related Questions