title: JavaScript Slider inside modal window
body: <p>I want to make a slider inside the modal window. I made the first part of my code: the modal window opens after clicking on the each picture. Now I make two buttons previous and next in the modal window, after clicking on that I want to go to the next image. And I can't understand how should I write js function for previous and next buttons. My code is below:</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;head&gt;
      &lt;title&gt;&lt;/title&gt;
      &lt;meta charset="uff-8"&gt;
      &lt;style&gt;
      .myImg{
          cursor:pointer;
          transition:0.3s;
      }
      .myImg:hover{
          opacity:0.7;
      }
      .modal{
          display:none;
          position:fixed;
          z-index:1;
          padding-top: 100px;
          left:0;
          top:0;
          width:100%;
          height: 100%;
          overflow:auto;
          background-color: rgb(0,0,0);
          background-color: rgba(0,0,0,0.9);
      }
      .modal-content{
          margin: auto;
          display: block;
          width:80%;
          max-width: 700px;
      }
      .modal-content{
          -webkit-animation-name:zoom;
          -webkit-animation-duration: 0.6s;
          animation-name:zoom;
          animation-duraion:0.6s;
      }
      /* Next &amp; previous buttons */
  .prev, .next {
    cursor: pointer;
    position: absolute;
    top: 0;
    top: 50%;
    width: auto;
    margin-top: -22px;
    padding: 16px;
    color: white;
    font-weight: bold;
    font-size: 18px;
    transition: 0.6s ease;
    border-radius: 0 3px 3px 0;
  }
  
  /* Position the "next button" to the right */
  .next {
    right: 0;
    border-radius: 3px 0 0 3px;
  }
  
  /* On hover, add a black background color with a little bit see-through */
  .prev:hover, .next:hover {
    background-color: rgba(0,0,0,0.8);
  }
      @-webkit-keyframes zoom{
          from {-webkit-transform:scale(0)}
          to {-webkit-transform:scale(1)}
      }
      @keyframes zoom {
      from {transform:scale(0)}
      to {transform:scale(1)}
      }
      .close{
          position: absolute;
          top:15px;
          right:35px;
          color:#f1f1f1;
          font-size: 40px;
          font-weight: bold;
          transition:0.3s;
      }
      .close:hover, .close:focus{
          color:#bbb;
          text-decoration: none;
          cursor:pointer;
      }
      @media only screen and (max-width: 700px){
          .modal-content{
              width: 100%;
          }
      }
  
  
      &lt;/style&gt;
  &lt;/head&gt;
  
  &lt;body&gt;
  
  &lt;img class="myImg" src="/img1" width="300" height="150"&gt;
  &lt;img class="myImg" src="/img2" width="300" height="150"&gt;
  &lt;img class="myImg" src="/img3" width="300" height="150"&gt;
  &lt;div id="myModal" class="modal"&gt;
      &lt;span class="close"&gt;X&lt;/span&gt;
      &lt;img class="modal-content" id="img01"&gt;
      &lt;a class="prev"&gt;&amp;#10094;&lt;/a&gt;
      &lt;a class="next"&gt;&amp;#10095;&lt;/a&gt;
  
  &lt;/div&gt;
  
  &lt;script&gt;
  
      var modal = document.getElementById("myModal");
      var img = document.getElementsByTagName('img');
      var modalImg = document.getElementById('img01');
      var prev = document.getElementsByClassName('prev');
      var next = document.getElementsByClassName('next');
      var i;
      var currentImage;
      for(i = 0; i&lt;img.length; i++){
          img[i].onclick = function(){
              modal.style.display = "block";
              modalImg.src = this.src;
              currentImage = this.img[i];
          }
      }
  
      prev.onclick = function(){
          modal.style.display = "block";
          modalImg.src = img.src;
      }
  
      var span = document.getElementsByClassName("close")[0];
  
      span.onclick = function() {
          modal.style.display = "none";
      }
  &lt;/script&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>