var imgArr; $(document).ready(function(){ preload(["/vehiclephotos/1143335/huge/4fe63b9f-7b1f-4b48-b9fa-bb7369cf4223.jpg"]); $("#photo-main").attr("src","/vehiclephotos/1143335/huge/4fe63b9f-7b1f-4b48-b9fa-bb7369cf4223.jpg"); }); function preload(arrayOfImages) { $(arrayOfImages).each(function(){ $('')[0].src = this; }); imgArr = arrayOfImages; }