var imgArr; $(document).ready(function(){ preload(["/vehiclephotos/1660082/huge/e966c7c6-67c0-4672-b25d-469b0f2c8bae.jpg"]); $("#photo-main").attr("src","/vehiclephotos/1660082/huge/e966c7c6-67c0-4672-b25d-469b0f2c8bae.jpg"); }); function preload(arrayOfImages) { $(arrayOfImages).each(function(){ $('')[0].src = this; }); imgArr = arrayOfImages; }