选择没有特定索引的子项(Jquery)

时间:2011-12-03 08:49:26

标签: javascript jquery children

我想选择一些没有特定索引的孩子,比如反向使用eq()。

我还需要能够将索引号作为变量传递。

1 个答案:

答案 0 :(得分:8)

$("#foo").children().not(":eq(2)");

这将选择foo除{3}之外的所有子项(eq()使用Javascript的0索引)。

Example

将变量传递给它:

var num = "2";
$("#foo").children().not(":eq(" + num + ")").css("background-color", "red");

Example