Reputation: 26336
My code is like 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?
Upvotes: 0
Views: 111
Reputation: 7614
$('#someSelector tr:nth-child(' + childNo + ' ) td:first span').addClass('font-strike');
Upvotes: 0
Reputation: 125674
you need to wrap your variable like :
$('#someSelector tr:nth-child('+childNo'+) td:first span').addClass('font-strike');
Upvotes: 0
Reputation: 12017
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
Upvotes: 1