views:

238

answers:

1

In the DOM I am loading a static Google Map image. When the document is ready with jQuery sometimes I need to replace that image with a bigger version. Problem is that in IE the CPU goes whooooooo because IE is still looking to load the initial image with no success. Is there a way to cancel or clear the previous load?

EDIT: I should note that I use .html() inside a function when SWFObject is not successfully embedded..

I am not able to reproduce the problem in following example, but basically I use this:

JS:

$(document).ready(function() {
    $("img#myImage").html('<img id="myImage" src="images/002.jpg" />');
});

HTML

<img id="myImage" src="images/001.jpg" />
+2  A: 

The .html() function replaces the HTML inside the img tag. Of course, there is no HTML in the img tag. Instead, use .attr():

$("img#myImage").attr('src', 'images/002.jpg');

Calling this immediately changes the source of the image and the browser should begin loading the new image.

Aaron
solved, cheers Aaron
FFish