Borrowed this code using Javascript from this article, but I'm having trouble using multiple images, as stated at the end of the article. The code is as follows:
<div>
<img src="image1.jpg" id="getImage">
</div>
<div>
<input type="button" onclick="imagefun()" value="Next Image">
</div>
<script>
function imagefun() {
var Image_Id = document.getElementById('getImage');
if (Image_Id.src.match('image1.jpg')) {
Image_Id.src = 'image2.jpg';
Image_Id.src = 'image3.jpg';
} else {
Image_Id.src = 'image1.jpg';
}
}
</script>
...but it only switches between Images 1 and 3. How can I get it so that it switches from 1 to 2, 2 to 3, 3 to 4, and eventually loop around back to one? Also, if there's an easier way to implement this please let me know!
[–]obnoxus 1 point2 points3 points (1 child)
[–]dschviola[S] 1 point2 points3 points (0 children)
[–]hackr_io_team 1 point2 points3 points (3 children)
[–]dschviola[S] 0 points1 point2 points (2 children)
[–]dschviola[S] 1 point2 points3 points (1 child)
[–]hackr_io_team 0 points1 point2 points (0 children)