How can I get a specific number child using CSS?

Satch3000 picture Satch3000 · Apr 14, 2011 · Viewed 284k times · Source

I have a table whose tds are created dynamically. I know how to get the first and last child but my question is:

Is there a way of getting the second or third child using CSS?

Answer

BoltClock picture BoltClock · Apr 14, 2011

For modern browsers, use td:nth-child(2) for the second td, and td:nth-child(3) for the third. Remember that these retrieve the second and third td for every row.

If you need compatibility with IE older than version 9, use sibling combinators or JavaScript as suggested by Tim. Also see my answer to this related question for an explanation and illustration of his method.