var imgArr; $(document).ready(function(){ preload(["/vehiclephotos/1177821/huge/27e944e0-8576-4173-a18a-9e497240bbdb.jpg"]); $("#photo-main").attr("src","/vehiclephotos/1177821/huge/27e944e0-8576-4173-a18a-9e497240bbdb.jpg"); }); function preload(arrayOfImages) { $(arrayOfImages).each(function(){ $('')[0].src = this; }); imgArr = arrayOfImages; }