Japeljoff
Japeljoff

Reputation: 21

How to call two nth-child in a table?

I have a table 4*5 (4 columns, 5 rows).

I want to add a class to the cells on the first column and after the 2nd row.

My code :

$("tr>td:nth-child(1) tr:nth-child(n+3)").addClass("ClassName");

This is not working. Any idea on how to do this?

PS. JsFiddle

Upvotes: 2

Views: 4812

Answers (2)

acdcjunior
acdcjunior

Reputation: 135862

To select cells that are both at the first column and after the 2nd row, use the CSS selector:

tr:nth-child(n+3) td:nth-child(1)

jQuery:

$("tr:nth-child(n+3) td:nth-child(1)").addClass("ClassName");

Your fiddle, updated: http://jsfiddle.net/CnUw6/1/

Upvotes: 1

nikoloza
nikoloza

Reputation: 976

You need a comma between your elements:

$("tr > td:nth-child(1), tr:nth-child(n+3)").addClass("ClassName");

Upvotes: 1

Related Questions