var imgArr; $(document).ready(function(){ preload(["/vehiclephotos/1163265/huge/eb9200d5-0355-4db1-9cfb-c52f00a8ba31.jpg", "/vehiclephotos/1163265/huge/c2a952dc-1c71-40e5-812c-8ae7010fe043.jpg", "/vehiclephotos/1163265/huge/3975988e-f547-43e5-aa93-ec9f6bff3f9f.jpg"]); $("#photo-main").attr("src","/vehiclephotos/1163265/huge/eb9200d5-0355-4db1-9cfb-c52f00a8ba31.jpg"); }); function preload(arrayOfImages) { $(arrayOfImages).each(function(){ $('')[0].src = this; }); imgArr = arrayOfImages; }