I am loading a list of images and adding a click event to each of them using Dojo so when user clicks an image, the ID for that image gets displayed. Please see codes below. Images were loaded, but when I click each of them, only '10143' was written in the log. any ideas why that happened? Please help!
var PictureIds = ['10141', '10142', '10143'];
var resultUl = domConstruct.create('ul');
for (i = 0; i < PictureIds.length; i++){
var image= domConstruct.create('img', {
id: PictureIds[i],
src: "./images/"+ PictureIds[i] + ".jpg",
class: "photo"});
var li= domConstruct.create('li');
domConstruct.place(image, li);
domConstruct.place(li, resultUl);
on(image, 'click', function(){
console.log(image.id);
});
}
domConstruct.place(resultUl,'pictures');
<div id="pictures"></div>