PDA

View Full Version : load javascript before images?



ranteo
01 Jan 2010, 08:27 AM
Hi, i have a javascript content toggler which loads only after my image loads. Is there a way to change the order such that the javascript/content loads first, and then the image?

Thanks.

LiteTest
01 Jan 2010, 07:17 PM
You can specify the images in javascript and then load them afterwards.

<img id="img1" />

and then in javascript you just get the element by id, and specify the src attribute.

In jQuery this would be even lovelier



$(document).ready(function() {
$("#img1").attr("src", "/Path/To/Image.jpg");
});


Edit:
On a sidenote: If you have your javascript in the header it will load before the images, but I take it you want to load all page elements before you load the images.