Perhaps another line of code?
$('#bgImage').attr('src','images/'+bgImage),
$('#searchPin').css("top",y+"px");
$('#searchPin').css("left",x+"px");
If you want to wait for the image to load, you are probably looking for an event load:
$('#bgImage').load(function() {
$('#searchPin').css("top",y+"px");
$('#searchPin').css("left",x+"px");
}).attr('src','images/'+bgImage);
Note that an event handler load(...)was created before the attribute was changed srcusing attr- in case of image caching.
If you do this several times, you might want to look into unbind.
source
share