Jump to content

[Object Htmlimageelement] - Why Am I Getting This?


next

Recommended Posts

I place several images into an array, then call the elements to change the picture, but instead changing source to a URL, my array stores: [object HTMLImageElement]?

Why???

if (this.id == 'next') {
if (images.length > i+1) {
i++;
} else {
if (i != 0)
i--;
}
document.getElementById('gallery').src = images[i];

that's the code.

 

Also, why my conditionals aren't working as supposed to? For instance I thought that:

if (images.length > i)

would stop the image swap, but it doesn't, unless I change it to the awkward version above, In my current example array had 2 elements and "i" is set to 0. I click the link once "i" becomes 1, then I click it again, but the conditional doesn't stop it even though "i" becomes a 2 (and if I understand correctly 2 isn't greater than 2).

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.