for (var x = 1; x <= i; x++){ $("#gra").append("<div></div>"); }; $("#gra").each( function(index){ cos[y] = "div:eq("+ y +")"; alert (cos[y]); $(this).find(cos[y]).attr("id", "pole_"+ y ); y++; }); $("#pole_0").html("test"); //tu ok $("#pole_5").html("test5"); //tu nie dziala ? co to moze byc