Adding alt tags to images within a javascript slideshow


New Member

I have been working on a site and have added a javascript slideshow and now I'm wondering how to add alt tags to the images?

imageArray = new Array();
imageArray[imageNum++] = new imageItem(imageDir + "5678000-01070.jpg");
imageArray[imageNum++] = new imageItem(imageDir + "5678000-01071.jpg");

Any pointers would be greatly appreciated...
images = new Array();
images[count++] = new ImageItem("5678000-01070.jpg", "alt tag for 1070");
images[count++] = new ImageItem("5678000-01071.jpg", "alt tag for 1071");

If you can, change the ImageItem constructor to take an extra parameter, which will become the alt tag. Something like,

function ImageItem(name, alt) {
  this.img = new Image();
  this.img.src = imageDir + url;
  this.alt = alt;

When you replace the image,

   imgObject.src = images[n].img.src;
   imgObject.alt = images[n].alt;

However, there are javascript animation libraries (eg scriptaculous) that you might prefer to use which will take care of appearing and disappearing images as well as giving you more interesting effects (slide up, slide down, fade in, fade out, etc).