For preloading images using the following code:
jQuery.preloadImages = function() { for(var i = 0; i < arguments.length; i++) { jQuery("<img>").attr("src", arguments[i]); } }; var imagesCount = $(".zoom").length; for (var i = 0; i < imagesCount; i++) { var img = $(".zoom:eq("+i+")").attr("data-image"); $.preloadImages(img); } How to click on the button with the zoom class to display the real width of the image? The button has a data-image attribute that contains the path to the image, and the image has already been loaded.