I have this code:
$(this).find('.placeholder-style td:nth-child(1)').addClass('hidden-td')
$(this).find('.placeholder-style td:nth-child(2)').addClass('hidden-td')
$(this).find('.placeholder-style td:nth-child(3)').addClass('hidden-td')
$(this).find('.placeholder-style td:nth-child(4)').addClass('hidden-td')
$(this).find('.placeholder-style td:nth-child(5)').addClass('hidden-td')
And I want to do it dynamic like this:
for (i = 0; i < 5; i++){
$(this).find('.placeholder-style td:nth-child'.(i)).addClass('hidden-td')
}
Which is the correct syntax to this code?
1instead of0and use<=instead of<. And use string concatenation (as indicated by Teemu below). And don't forget to usevar i.foreach?+operator has used to be a string concatenation operator in JS ...$(this).find('.placeholder-style td').filter( function(idx){ return idx < 5 }).addClass('hidden-td')