Hey. I want to pass a variable as an argument into an nth-child selector.
This doesn't work:
var position = 5;
$("#daddy > div:nth-child(position)").animate({
opacity: 0.01,
}, 500);
Is it possible though? Cheers, Jack
Hey. I want to pass a variable as an argument into an nth-child selector.
This doesn't work:
var position = 5;
$("#daddy > div:nth-child(position)").animate({
opacity: 0.01,
}, 500);
Is it possible though? Cheers, Jack
Try:
var position = 5;
$("#daddy > div:nth-child(" + position + ")").animate({
opacity: 0.01,
}, 500);
You need quoting:
var position = 5;
$("#daddy > div:nth-child(" + position + ")").animate({
opacity: 0.01,
}, 500);
Try:
var position = 5;
$("#daddy > div:nth-child(" + position + ")").animate({
opacity: 0.01,
}, 500);