var imgArr; $(document).ready(function(){ preload(["/vehiclephotos/1097110/huge/f9b17b0c-426e-4abf-9d6b-76810b8f458d.jpg"]); $("#photo-main").attr("src","/vehiclephotos/1097110/huge/f9b17b0c-426e-4abf-9d6b-76810b8f458d.jpg"); }); function preload(arrayOfImages) { $(arrayOfImages).each(function(){ $('')[0].src = this; }); imgArr = arrayOfImages; }