for(var i=0; i<imgs.length; i++){ imgs[i].index = i; imgs[i].onclick = function (){ console.log(this.index) document.body.style.background = "url(images/"+this.index+".jpg) no-repeat"; } }
for(var i=0; i<imgs.length; i++){ imgs[i].index = i; imgs[i].onclick = function (){ console.log(this.index) document.body.style.background = "url(images/"+this.index+".jpg) no-repeat"; } }