JQuery: how to select every cell in a table except the last in each row?

I want every cell in every row except the last in each row. I tried:

$("table tr td:not(:last)") 

but that seems to have given me every cell except the last one in the table. Not quite what I want.

I'm sure it is simple, but I still hug the selectors.

+7
javascript jquery
source share
4 answers

Try:

 $('table tr td:not(:last-child)') 
+24
source share

You can try

 $("table td:not(:last-child)") 

or

 $("table td:not(:nth-child(n))") 

where n is an index based on 1 child

or

 $("table td").not(":last-child") 
+7
source share

Try the selector of the latter. It:

 $("table tr td:not(:last-child)") 

selects all cells in all rows except the cells in the last column.

+3
source share

fwiw I found your original work just fine (maybe an improvement in core jQ since 2009?) ...

 $("#myTable thead th:not(:last)").css("border-right","1px solid white"); 

The title bar of my table has a dark blue background, so the white frame on the right made the table look snaggletoothed and did not match the black border of 1px data.

0
source share

All Articles