views:

1387

answers:

3

I want every cell in each 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 very last in the table. Not quite what I want.

I'm sure this is simple but I'm still wrapping my head around the selectors.

+10  A: 

Try

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

:)

Ricardo Vega
From the documentation: While :last matches only a single element, this matches more then one: One for each parent.
dbrien
And the winner by chronological order... :)
cletus
+3  A: 

Try the last-child selector. This:

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

will select all cells in all rows except of the cells in the last column.

kgiannakakis
the tr is unnecessary as by default jquery does not look for immediate descendants - to get the immediate descendants only, you need to use the > "operator"
DrJokepu
+5  A: 

You could try

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

or

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

where n is 1-based index of a child element

or

$("table td").not(":last-child")
mipi
+1 for the nth-child mention.
cletus