如何在jQuery中组合两个过滤器?

时间:2011-11-28 19:52:33

标签: jquery

我正在使用jQuery 1.6.2

我试图将表格的第一个和最后一个单元格变为黄色。

基本上,我使用两行代码来完成此任务。

$("tr:first").children("td:first").css("background", "yellow");
$("tr:first").children("td:last").css("background", "yellow");

如何将两个滤镜组合在一起以获得连续的第一个和最后一个tds?

2 个答案:

答案 0 :(得分:10)

$("tr:first").children("td:first, td:last").css("background", "yellow");

答案 1 :(得分:1)

在jQuery中,您可以使用逗号分隔多个选择器:

$("tr:first").children("td:first, td:last").css("background", "yellow");

以下是“多选择器”的jQuery文档:http://api.jquery.com/multiple-selector/

总的来说,jQuery使用Sizzle Selction Engine,它的语法基于CSS语法(http://sizzlejs.com/)。

相关问题