I can not find an error in my code. The code should add a different id to all table cells. And the same is added to all of them, what's the problem?
$('.price-table td').each(function(){ var i = 0; i < 1000; i++; $(this).attr("id",+i); }); I can not find an error in my code. The code should add a different id to all table cells. And the same is added to all of them, what's the problem?
$('.price-table td').each(function(){ var i = 0; i < 1000; i++; $(this).attr("id",+i); }); Note the callback function parameters.
$('.price-table td').each(function(index, element) { $(element).attr("id", "id_" + index); }); You can without each :
$('.price-table td').attr("id", function(index, oldAttr) { return "id_" + index; }); Regarding your code:
Try to explain to yourself what each line / function / operator does in it.
$('.price-table td').each(function(key, value){ $(this).attr('id', key); }); Source: https://ru.stackoverflow.com/questions/622683/
All Articles