Japeljoff Japeljoff - 1 month ago 8
jQuery Question

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

Answer

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/

Comments