1

I want to make slide show using html css and js. for that i write the code and i am getting the slide shows. but every time at the beginning it creates a blank image named image which i wrote at alt tag.how to remove that?

<img id="myPhoto" src="images.jpg" alt="image">
<script src="slideshow.js"></script>

my javascript is

var myImage=document.getElementById("myPhoto");

var imageArray=["images.jpg","image1.jpg","images2.jpg","images3.jpg","images4.jpg"];

var imageIndex=0;

function changeImage()
{
    myPhoto.setAttribute("src", imageArray[imageIndex]);
    imageIndex++;
    if(imageIndex>=imageArray.length){
            imageIndex=0;
            }

    }

var intervalHandle = setInterval(changeImage,3000);


myPhoto.onclick=function(){
    clearInterval(intervalHandle)
    }
8
  • 1
    You appear to have a syntax error "images4.$... Commented Jul 16, 2015 at 7:07
  • that was a print mistake Commented Jul 16, 2015 at 7:15
  • You are getting myImage with js, but you are calling myPhoto.setAttribute. Change myPhoto to myImage Commented Jul 16, 2015 at 7:16
  • Is your slide show working except for the beginning? Commented Jul 16, 2015 at 7:23
  • Note you still and a typo, you forgot the jpg". Also make sure to wait until the images load before starting your interval. Why do you want to remove your first image? Do you mean it's blank when it shouldn't be? Commented Jul 16, 2015 at 7:25

2 Answers 2

1

your code works fine. onething i have noticed in your javascript imageArray all the image has named images2,images3, etc except image1.jpg. I think there may be a silly mistake for these. because alt shows the message if it didn't find the image. otherwise your code is a nice one to made slide show.

Sign up to request clarification or add additional context in comments.

Comments

1

Your code seems does not have any problems. I copied your code and write a slideshow program. It is working fine as expected.

As for the problem you mentioned, I think you can do this:

  1. make sure your "images.jpg" exists. I tried to purposely include an image that does not exist, it shows "a blank image named image" as you mentioned in the question. Therefore, I think you may include your image wrongly. For me, as long as the image source is correctly included, problems resolved.

  2. you may want to read more about the "alt" attribute in the img tag. I think in your case, alt is not necessary. You can just set it to alt="". For more information about when to use "alt" attribute in the img tag, you may want to refer to this url: http://www.w3.org/QA/Tips/altAttribute

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.