var imgArr; $(document).ready(function(){ preload(["/vehiclephotos/1666111/huge/914d2615-6170-4308-8e1c-12404295a2c5.jpg"]); $("#photo-main").attr("src","/vehiclephotos/1666111/huge/914d2615-6170-4308-8e1c-12404295a2c5.jpg"); }); function preload(arrayOfImages) { $(arrayOfImages).each(function(){ $('')[0].src = this; }); imgArr = arrayOfImages; }