开发者

jquery nth-child issue

My code is 开发者_如何学Golike this:

var childNo = 2;
$('#someSelector tr:nth-child(childNo) td:first span').addClass('font-strike');

but it doesn't add the class. If i replace childNo with 2 it works fine. any idea how i can get it to work?


you're putting the string literal 'childNo' into your selector. replace it with:

$('#someSelector tr:nth-child('+childNo+') td:first span').addClass('font-strike');

and it should work


you need to wrap your variable like :

$('#someSelector tr:nth-child('+childNo'+) td:first span').addClass('font-strike');


$('#someSelector tr:nth-child(' + childNo + ' ) td:first span').addClass('font-strike');

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜