var index=1;
showPics(index);
function showPics(n) {
var i;
var j = document.getElementsByClassName("gpic");
if (n > j.length) {index = 1;}
if (n < 1) {
index = x.length;
}
for (i = 0; i < j.length; i++) {
x[i].style.display = "none";
}
j[index-1].style.display = "block";
}
function showNext(x) {
showPics(index += x);
}
At the document.getElementsByClassName() part somehow "j" doesn't get the elements. as you can see there . This is the html part of the problem:
<div position="relative" img=bigimg>
<button position="absolute" id=leftbtn onclick="showNext(-1);"></button>
<img class="gpic" src='../images/0.jpg'>
<img class="gpic" src ='../images/1.jpg'>
<img class="gpic" src ='../images/2.jpg'>
<img class="gpic" src = '../images/3.jpg'>
<img class="gpic" src ='../images/4.jpg'>
<img class="gpic" src ='../images/5.jpg'>
<img class="gpic" src ='../images/6.jpg'>
<img class="gpic" src ='../images/7.jpg'>
<img class="gpic" src ='../images/8.jpg'>
<button position="absolute" id=rightbtn onclick="showNext(1);"></button>
I don't know what causes the problem. I just trying to do something like this: https://www.w3schools.com/w3css/tryit.asp?filename=tryw3css_slideshow_self