0

I am using the below code to replace the first image within a div. Is it possible to preempt an image loading and replace it before it's in? The method below works, but of course the initial image loads then replaces when this loads on DOM ready.

var image = $('.promo-unit-site-logo-3').find('img:first').attr('src', 'blank');
console.log(image.attr('src'));

Cheers, John

  • 1
    No, you can't replace the source before the element is available in the DOM, and by that time the original source has already started loading. – adeneo Oct 13 '16 at 19:18
  • you can put your code in $(function(){ // HERE }); – Netzach Oct 13 '16 at 19:18
  • Rather than thinking of it as loading an image then replacing it, why not think of having it blank to start with and [preloading the image](http://stackoverflow.com/questions/476679/preloading-images-with-jquery) for when you actually need it? – Mike Cluck Oct 13 '16 at 19:21

0 Answers0