Reputation: 393
I have this simple code to load an image array and increment through it using an img src in a div. It works fine in Firefox but Chrome and IE11 aren't working. I've tested javascript using an alert and it's working in both browsers. What am I missing? Thanks!
var counter = -1;
var imgArray = new Array();
imgArray[0] = new Image();
imgArray[0].src = "../Images/NewLogo1.jpg";
imgArray[1] = new Image();
imgArray[1].src = "../Images/NewLogo2.jpg";
function nextImage(){
//increments the counter and shows the next image
counter++;
if (counter > 1){
counter = 0;
} // end if
document.fadeImg.src = imgArray[counter].src;
} // end nextImage
setInterval(function() {
nextImage();
},5000);
onload = nextImage;
HTML
<div class="homecontent" id="homecontent">
<img id="fadeImg" src="holder.jpg" alt="" />
</div>
Upvotes: 0
Views: 215
Reputation: 460
If you use id attribute (e.g. <img id="fadeImg"... />
) in your HTML, then you can select it using this syntax: document.getElementById("fadeImg").src
.
However, if you use name attribute (e.g. <img name="fadeImg"... />
) in your HTML, then you can select it using the following syntax: document.fadeImg.src
.
Upvotes: 1