Member Offer
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Adding alt tags to images within a javascript slideshow

Discussion in 'Website Coding & Programming Forum:' started by rachel84, Mar 20, 2009.

  1. rachel84

    rachel84 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...
  2. conanite

    conanite New Member

    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).

Share This Page