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.
我确信这很简单,但我仍然围绕着选择器。
4 个解决方案
#1
Try:
$('table tr td:not(:last-child)')
#2
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
其中n是子元素的从1开始的索引
or
$("table td").not(":last-child")
#3
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.
将选择除最后一列中的单元格之外的所有行中的所有单元格。
#4
fwiw I found your original works just fine (maybe an enhancement to main jQ since 2009?)...
fwiw我发现你原来的作品很好(可能是自2009年以来主要jQ的增强?)......
$("#myTable thead th:not(:last)").css("border-right","1px solid white");
The header row of my table has navy background so the white border on the right made the table look snaggletoothed and not match the black 1px border of the data
我的表格的标题行有海军背景,所以右边的白色边框使表格看起来像是一样,并且不匹配数据的黑色1px边框
#1
Try:
$('table tr td:not(:last-child)')
#2
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
其中n是子元素的从1开始的索引
or
$("table td").not(":last-child")
#3
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.
将选择除最后一列中的单元格之外的所有行中的所有单元格。
#4
fwiw I found your original works just fine (maybe an enhancement to main jQ since 2009?)...
fwiw我发现你原来的作品很好(可能是自2009年以来主要jQ的增强?)......
$("#myTable thead th:not(:last)").css("border-right","1px solid white");
The header row of my table has navy background so the white border on the right made the table look snaggletoothed and not match the black 1px border of the data
我的表格的标题行有海军背景,所以右边的白色边框使表格看起来像是一样,并且不匹配数据的黑色1px边框