Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Preloading images and adding class

I am using the following code to preload my images:

function preload(sources)
{
  var images = [];
  for (i = 0, length = sources.length; i < length; ++i) {
    images[i] = new Image();
    images[i].src = sources[i];
  }
}

How can I add a class to the image object? I tried images[i].class = 'classname', but this doesn't do the trick. Any suggestions?

Thanks!

like image 912
The Code Buccaneer Avatar asked Feb 10 '12 15:02

The Code Buccaneer


People also ask

What does preloading an image do?

Preload lets you tell the browser about critical resources that you want to load as soon as possible, before they are discovered in HTML. This is especially useful for resources that are not easily discoverable, such as fonts included in stylesheets, background images, or resources loaded from a script.


1 Answers

Use className instead of class.

images[i].className  = "className";
like image 117
ShankarSangoli Avatar answered Oct 29 '22 13:10

ShankarSangoli