Best explained with code:
$(".myParent .myChild:nth-child(3n)").css('border-top-color','#ffffff');
√ Works
myVar = "3n";
$(".myParent .myChild:nth-child(myVar)").css('border-top-color','#ffffff');
X Doesn't work
T开发者_JS百科his is obviously jQuery programming 101... but seriously, why on earth won't that work?! I'm passing on the same thing!
I tried it as > myVar = 3n (no string), obviously that shouldn't work, and it didn't.
you var has to be concatenated
var myVar = "3n";
$(".myParent .myChild:nth-child("+myVar+")").css('border-top-color','#ffffff');
精彩评论