I tried to create a gallery, if you click on the picture, then a new model box is shown, in this window there is next and back button but it doesn't work
console.log("jdkf");
var expandImg = document.getElementById("expandedImg");
let img = document.getElementsByClassName("pic");
let contener = document.getElementById("container");
for (let i = 0; i < img.length; i++) {
img[i].addEventListener("click", (event) => {
let cur = event.target;
contener.style.display = "block"
expandImg.src = cur.src;
})
}
function next() {
img[i].nextSibling
}
function back() {
img[i].previousSibling
}
body {
padding: 0;
margin: 0;
box-sizing: border-box;
}
#content {
position: absolute;
top: 50%;
left: 50%;
margin-right: -50%;
transform: translate(-50%, -50%);
}
.pic.active {
opacity: 0.5;
}
.pic-large {
cursor: pointer;
}
#expandedImg {
width: 700px;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
transition: all 0.5s;
}
/* The expanding image container */
.container {
display: none;
/* Hidden by default عكسها block */
position: fixed;
/* Stay in place */
z-index: 1;
/* Sit on top */
padding-top: 100px;
/* Location of the box */
left: 0;
top: 0;
width: 100%;
/* Full width */
height: 100%;
/* Full height */
overflow: auto;
/* Enable scroll if needed */
background-color: rgb(252, 252, 252);
/* Fallback color */
background-color: rgba(255, 255, 255, 0.8);
/* Black w/ opacity */
}
/* Expanding image text */
#imgtext {
position: absolute;
bottom: 15px;
left: 15px;
color: white;
font-size: 20px;
}
/* Closable button inside the expanded image */
.closebtn {
position: absolute;
top: 10px;
right: 15px;
color: #000;
font-size: 35px;
cursor: pointer;
}
#btn {
position: absolute;
top: 80%;
left: 50%;
z-index: 2;
}
<div class="container" id="container">
<div id="btn">
<input type="button" value="Next" onclick="next()" id="next">
<input type="button" value="previous" onclick="back()" id="back">
</div>
<span onclick="this.parentElement.style.display='none'" class="closebtn">×</span>
<img id="expandedImg">
<div id="imgtext"></div>
</div>
<div id="content">
<img class="pic active" src="https://picsum.photos/id/200/200/200" alt="">
<img class="pic" src="https://picsum.photos/id/400/200/200" alt="">
<img class="pic" src="https://picsum.photos/id/201/200/200" alt="">
<img class="pic" src="https://picsum.photos/id/450/200/200" alt="">
</div>