var imgArr; $(document).ready(function(){ preload(["/vehiclephotos/1170357/huge/d3b87cc6-d13e-4c30-8aca-a391b8eb9212.jpg"]); $("#photo-main").attr("src","/vehiclephotos/1170357/huge/d3b87cc6-d13e-4c30-8aca-a391b8eb9212.jpg"); }); function preload(arrayOfImages) { $(arrayOfImages).each(function(){ $('')[0].src = this; }); imgArr = arrayOfImages; }