Peter V
Peter V

Reputation: 2488

Hiding specific HTML table cells with JavaScript

I have found other questions through which I learned how to hide the first row and the (first row's) first cell using;

$('table#truetable tr:first').hide();

and

$('table#truetable td:first').hide();

But what if I want to hide for example the first cell of the second row using this approach?

Upvotes: 0

Views: 784

Answers (3)

Luka
Luka

Reputation: 341

theres a css selector for this:

:nth-child(N)

N is the index of the child +1 in the selection

Upvotes: 0

gdoron
gdoron

Reputation: 150253

$('#truetable tr:eq(1) td:first').hide();

:eq docs

jQuery(':eq(index)')

index
Zero-based index of the element to match.

Upvotes: 2

Mitya
Mitya

Reputation: 34556

$('table#truetable tr:eq(1) td:first-child').hide();

Upvotes: 2

Related Questions