First declare your variables (whether using var or let) in order to avoid created global variables, and then you can either add the id within the loop:
for(let i=0; i<10; i++){ $('.d').append('<img src="" id="' + i + '" class="UP__" width="120" height="120">'); }
Or do so outside of the loop:
for(let i=0;i<10;i++){ $('.d').append('<img src="" class="UP__" width="120" height="120">'); } // here we select all the matching <img> elements, and update // 'id' property using the prop() method, and the anonymous // function: $('.d img').prop('id', function (index){ // 'index' is the index of the current element in // the jQuery collection over which prop() iterates: return index; });
The problem with your posted approach was that you were selecting all the matching elements (in each iteration of the loop) and setting the id of all those elements to the same number. This is avoided by both approaches shown above.
Note that using a numeric character as the first character of an id does complicate the CSS selectors used to target those ids as you first need to escape the number character.
With that in mind, to select the element with id="1" you'd need to use:
#\31 { /* css */ }
i1,i2....