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');
精彩评论