var imgArr; $(document).ready(function(){ preload(["/vehiclephotos/1661308/huge/10f5fa50-f954-4d9b-9027-05d4dfaeeedb.jpg"]); $("#photo-main").attr("src","/vehiclephotos/1661308/huge/10f5fa50-f954-4d9b-9027-05d4dfaeeedb.jpg"); }); function preload(arrayOfImages) { $(arrayOfImages).each(function(){ $('')[0].src = this; }); imgArr = arrayOfImages; }