var imgArr; $(document).ready(function(){ preload(["/vehiclephotos/1006162/huge/ccf8672f-bb95-47d2-9577-1d69c8beb92c.jpg", "/vehiclephotos/stock/large/ce192c9a-0823-48f0-b0ec-a634c745980a.jpg"]); $("#photo-main").attr("src","/vehiclephotos/1006162/huge/ccf8672f-bb95-47d2-9577-1d69c8beb92c.jpg"); }); function preload(arrayOfImages) { $(arrayOfImages).each(function(){ $('')[0].src = this; }); imgArr = arrayOfImages; }