var imgArr; $(document).ready(function(){ preload(["/vehiclephotos/stock/large/7916f057-15b8-4c00-ab69-d43491faa228.jpg"]); $("#photo-main").attr("src","/vehiclephotos/stock/large/7916f057-15b8-4c00-ab69-d43491faa228.jpg"); }); function preload(arrayOfImages) { $(arrayOfImages).each(function(){ $('')[0].src = this; }); imgArr = arrayOfImages; }