jquery - 变量nth-child?

时间:2010-08-24 14:11:20

标签: jquery jquery-selectors

嘿。我想将变量作为参数传递给第n个子选择器 这不起作用:

var position = 5;

$("#daddy > div:nth-child(position)").animate({
    opacity: 0.01,
}, 500);​

虽然可以吗? 干杯,杰克

3 个答案:

答案 0 :(得分:34)

尝试:

var position = 5;

$("#daddy > div:nth-child(" + position + ")").animate({
    opacity: 0.01,
}, 500);​

答案 1 :(得分:4)

你需要引用:

var position = 5;

$("#daddy > div:nth-child(" + position + ")").animate({
   opacity: 0.01,
}, 500);​

答案 2 :(得分:4)

尝试:

var position = 5;

$("#daddy > div:nth-child(" + position + ")").animate({
    opacity: 0.01,
}, 500);​