JSFiddle - React, Tailwind, and code Playground

HTML

<img data-img-src="http://www.lubasf.com/blog/wp-content/uploads/2009/03/gnome.jpg" style="display: none" />

<img data-img-src="http://buffered.io/uploads/2008/10/gnome.jpg" style="display: none" />

JavaScript

(function(jQuery) {
jQuery.fn.loadImages = function(callbackFunc) { 
    var numToLoad = jQuery(this).length;
    var numLoaded = 0;
    return jQuery(this).each(function() { 
        if(jQuery(this).attr('src') == undefined) {
            jQuery(this).load(function() {
                numLoaded++;
                if(numToLoad == numLoaded)
                    callbackFunc();
            }).attr('src', jQuery(this).attr('data-img-src'));
        } else {
            numLoaded++;
            if(numToLoad == numLoaded)
                callbackFunc();
        }
    });
};
})(jQuery);

jQuery(function($){    // jQuery is the same as $, and it passes itself to the function
    $('img[data-img-src]').loadImages(donePreloading).show(function() { alert('showing'); });
});

function donePreloading() {
    alert('all done');
}