next Posted December 2, 2012 Share Posted December 2, 2012 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). Link to comment https://forums.phpfreaks.com/topic/271508-object-htmlimageelement-why-am-i-getting-this/ Share on other sites More sharing options...
next Posted December 3, 2012 Author Share Posted December 3, 2012 nvm I figured it out. I guess images is a built in array and I can't be using that name, and my If statement had a faulty logic. Link to comment https://forums.phpfreaks.com/topic/271508-object-htmlimageelement-why-am-i-getting-this/#findComment-1397035 Share on other sites More sharing options...
requinix Posted December 3, 2012 Share Posted December 3, 2012 It's not. images is an array of objects that your code set up somewhere. Try images.src instead. Link to comment https://forums.phpfreaks.com/topic/271508-object-htmlimageelement-why-am-i-getting-this/#findComment-1397044 Share on other sites More sharing options...
next Posted December 3, 2012 Author Share Posted December 3, 2012 Yeah I tried that as well, wasn't really getting anywhere, but as soon as I changed the array name to "pics" it worked without an issue. Weird. Link to comment https://forums.phpfreaks.com/topic/271508-object-htmlimageelement-why-am-i-getting-this/#findComment-1397193 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.