var imgArr; $(document).ready(function(){ preload(["/vehiclephotos/1200169/huge/d0e71b25-9485-4c72-bfe6-05f97b80da08.jpg"]); $("#photo-main").attr("src","/vehiclephotos/1200169/huge/d0e71b25-9485-4c72-bfe6-05f97b80da08.jpg"); }); function preload(arrayOfImages) { $(arrayOfImages).each(function(){ $('')[0].src = this; }); imgArr = arrayOfImages; }