Next image button [closed]

Trying to make next button but doesn’t work. https://jsfiddle.net/vd89ekrf/6/

var modal = document.getElementById('myModal');

var images = document.getElementsByClassName('myImages');
var modalImg = document.getElementById('img01');
var captionText = document.getElementById('caption');
for (var i = 0; i < images.length; i++) {
  var img = images[i];
  img.onclick = function() {
    modal.style.display = 'block';
    modalImg.src = this.src;
    captionText.innerHTML = this.alt;
  };
}
var span = document.getElementsByClassName('close')[0];

span.onclick = function() {
  modal.style.display = 'none';
};

var nextimage = document.getElementById('next');
for (var i = 0; i < images.length; i++) {
  var currentImage = images[i];
  nextimage.onclick = function() {
    currentImage++;
  };
}
.frame {
  margin: auto;
}

.column {
  max-width: 25%;
  flex: 25%;
  padding: 0 0%;
}

.column img {
  vertical-align: middle;
  width: 100%;
  padding: 10% 10%;
}

body {
  margin: auto;
  max-width: 1500px;
  background-image: linear-gradient(135deg, #4da0b0, #d39d38);
}

.picFrame {
  display: flex;
  flex-wrap: wrap;
  margin: auto;
  transition opacity: .25s ease-in-out;
}

.myImages {
  border-radius: 50%;
}

.myImages:hover {
  opacity: 0.7;
  cursor: pointer;
}

div {
  display: block;
}

.searchBar {
  text-align: center;
}

input {
  width: 450px;
  font-size: 20px;
  padding: 10px;
  margin: 2% auto;
  border: solid rgb(204, 203, 203);
  border-radius: 25px;
}

.modal {
  display: none;
  position: fixed;
  z-index: 1;
  padding-top: 100px;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  overflow: none;
  background-color: rgb(0, 0, 0);
  background-color: rgba(0, 0, 0, 0.9);
  outline: 1px blue;
}

.modal-content {
  display: flex;
  left: 0px;
  right: 0px;
  margin-left: auto;
  margin-right: auto;
  max-width: 1000px;
}

.modal-content,
#caption {
  -webkit-animation-name: zoom;
  -webkit-animation-duration: 0.6s;
  animation-name: zoom;
  animation-duration: 0.6s;
}

.close {
  position: absolute;
  top: 15px;
  right: 35px;
  color: #fffefe;
  font-size: 40px;
  font-weight: bold;
  transition: 0.3s;
}

.close:hover,
.close:focus {
  color: rgb(143, 143, 143);
  text-decoration: none;
  cursor: pointer;
}

.prev,
.next {
  cursor: pointer;
  position: absolute;
  top: 50%;
  width: auto;
  color: white;
  font-weight: bold;
  transition: 0.6s;
  font-size: 40px;
}

.prev:hover,
.next:hover {
  transition: 0.35s;
  transform: scale(2);
}

.next {
  right: 5%;
}

.prev {
  left: 5%;
}
<div class="frame">
  <div class="picFrame">
    <div class="column">
      <img class="myImages" id="myImg" src="http://cdn.cnn.com/cnnnext/dam/assets/181010131059-australia-best-beaches-cossies-beach-cocos3.jpg" />
      <div id="myModal" class="modal">
        <span class="close">&times;</span>
        <a class="prev">&#10094;</a>
        <a class="next">&#10095;</a>
        <img class="modal-content" id="img01" />
        <div id="caption">Description</div>
      </div>
      <img class="myImages" id="myImg" src="https://hips.hearstapps.com/hmg-prod.s3.amazonaws.com/images/beach-quotes-1559667853.jpg" />
      <div id="myModal" class="modal">
        <img class="modal-content" id="img01" />
        <div id="caption">Description</div>
      </div>
    </div>
  </div>
</div>

Answer

You are trying to select the next button using the id “next” (which doesn’t exist). Also, there are issues in selecting the next image.

Working code:

  

  var modal = document.getElementById('myModal');
var images = document.getElementsByClassName('myImages');
var modalImg = document.getElementById('img01');
var captionText = document.getElementById('caption');
            
  for (var i = 0; i < images.length; i++) {
    var img = images[i];
    img.onclick = function () {
      const currentImage = images[currentImageIndex];
      modalImg.src = this.src;
      captionText.innerHTML = this.alt;
      modal.style.display = 'block';
    };
  }
            
  var span = document.getElementsByClassName('close')[0];

  span.onclick = function () {
    modal.style.display = 'none';
    currentImageIndex = 0; // reset index
  };

var currentImageIndex = 0;

const currentImage = images[currentImageIndex];

var nextimage = document.getElementById('next');

 nextimage.onclick = function () {
     if (images[currentImageIndex + 1]) {
      currentImageIndex++;
      const currentImage = images[currentImageIndex];
      modalImg.src = currentImage.src;
      captionText.innerHTML = currentImage.alt;
      modal.style.display = 'block';
     }
};
.frame {
  margin: auto;
}

.column {
  max-width: 25%;
  flex: 25%;
  padding: 0 0%;
}

.column img {
  vertical-align: middle;
  width: 100%;
  padding: 10% 10%;
}

body {
  margin: auto;
  max-width: 1500px;
  background-image: linear-gradient(135deg, #4da0b0, #d39d38);
}

.picFrame {
  display: flex;
  flex-wrap: wrap;
  margin: auto;
  transition opacity: .25s ease-in-out;
}

.myImages {
  border-radius: 50%;
}

.myImages:hover {
  opacity: 0.7;
  cursor: pointer;
}

div {
  display: block;
}

.searchBar {
  text-align: center;
}

input {
  width: 450px;
  font-size: 20px;
  padding: 10px;
  margin: 2% auto;
  border: solid rgb(204, 203, 203);
  border-radius: 25px;
}

.modal {
  display: none;
  position: fixed;
  z-index: 1;
  padding-top: 100px;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  overflow: none;
  background-color: rgb(0, 0, 0);
  background-color: rgba(0, 0, 0, 0.9);
  outline: 1px blue;
}

.modal-content {
  display: flex;
  left: 0px;
  right: 0px;
  margin-left: auto;
  margin-right: auto;
  max-width: 1000px;
}

.modal-content,
#caption {
  -webkit-animation-name: zoom;
  -webkit-animation-duration: 0.6s;
  animation-name: zoom;
  animation-duration: 0.6s;
}

.close {
  position: absolute;
  top: 15px;
  right: 35px;
  color: #fffefe;
  font-size: 40px;
  font-weight: bold;
  transition: 0.3s;
}

.close:hover,
.close:focus {
  color: rgb(143, 143, 143);
  text-decoration: none;
  cursor: pointer;
}

.prev,
.next {
  cursor: pointer;
  position: absolute;
  top: 50%;
  width: auto;
  color: white;
  font-weight: bold;
  transition: 0.6s;
  font-size: 40px;
}

.prev:hover,
.next:hover {
  transition: 0.35s;
  transform: scale(2);
}

.next {
  right: 5%;
}

.prev {
  left: 5%;
}
<div class="frame">
  <div class="picFrame">
    <div class="column">
      <img class="myImages" id="myImg" src="http://cdn.cnn.com/cnnnext/dam/assets/181010131059-australia-best-beaches-cossies-beach-cocos3.jpg" />
      <div id="myModal" class="modal">
        <span class="close">&times;</span>
        <a class="prev">&#10094;</a>
        <a id = "next" class="next">&#10095;</a>
        <img class="modal-content" id="img01" />
        <div id="caption">Description</div>
      </div>
      <img class="myImages" id="myImg" src="https://hips.hearstapps.com/hmg-prod.s3.amazonaws.com/images/beach-quotes-1559667853.jpg" />
      <div id="myModal" class="modal">
        <img class="modal-content" id="img01" />
        <div id="caption">Description</div>
      </div>
    </div>
  </div>
</div>