views:

32

answers:

2

hi,

i built my own form-script and would like to preload a "loading"-icon which shows up when hitting the submit button.

i'm using this code:

var icon = $('<img />').attr('src', 'images/status.gif');

my question: will the image be cached + show up immidiately also when using jQuery for creating the icon's html-markup? like:

statusDiv.html("<img src='images/status.gif'> Submitting ..");

thx

+2  A: 

Yes, the image will be pulled from cache when doing this :) It's not jQuery specifically, this is just native browser behavior, whatever way you create the image should work.

The exception here is Opera IIRC, it won't preload the image by default since it realizes it's not being displayed yet, barring that case it should behave like you want.

The other possible case is the image hasn't yet had time to load, e.g. if I clicked submit really fast after loading the page, but this should be pretty unlikely, and the request to get the image should already be running.


As an aside, you can shorten the preload if it's just for this image:

var icon = $('<img src="images/status.gif" />');
Nick Craver
+1  A: 

Maybe you could try to place it on the right place, just with XHTML, and make it invisible with CSS. I guess it will be loaded, and on click you make it visible.

You can check your net tab in firebug.

Please let us know of that works.

Ronn0