I have an image gallery and i want to open each image using modal when click on each

  css, html, javascript

I build an image gallery with 13 photos that i found in w3school and I rebuilt for my own needs, the gallery looks nice, but the thing is that I can open only the first image using modal and I edited
a of javascript code snippe that I also found in w3schools, but works just for the first one image not for the rest, I’m novice working with javascript and I want to improve this opening each image of the gallery using modal when I touch or click each image.
This is the code what i’m using.

// Get the modal
var modal = document.getElementById("myModal");
// Get the image and insert it inside the modal - use its "alt" text as a caption
var img = document.getElementById("image-gall-1");
var modalImg = document.getElementById("img01");
var captionText = document.getElementById("caption-gallery-fu-sc");
img.onclick = function(){
  modal.style.display = "block";
  modalImg.src = this.src;
  captionText.innerHTML = this.alt;
// Get the <span> element that closes the modal
var span = document.getElementsByClassName("close-gallery-fu-sc")[0];
// When the user clicks on <span> (x), close the modal
span.onclick = function() { 
  modal.style.display = "none";
.row {
  display: -ms-flexbox; /* IE 10 */
  display: flex;
  -ms-flex-wrap: wrap; /* IE 10 */
  flex-wrap: wrap;
  padding: 0 4px;

/* Create two equal columns that sits next to each other */
.column {
  -ms-flex: 50%; /* IE 10 */
  flex: 50%;
  padding: 60px 4px;

.column img {
  margin-top: 8px;
  vertical-align: middle;
/* Style the Image Used to Trigger the Modal */
#image-gall-1,#image-gall-2,#image-gall-3,#image-gall-4,#image-gall-5,#image-gall-6,#image-gall-7,#image-gall-8,#image-gall-9,#image-gall-10,#image-gall-11,#image-gall-12,#image-gall-13 {
  border-radius: 5px;
  cursor: pointer;
  transition: 0.3s;
#image-gall-1:hover, #image-gall-2:hover, #image-gall-3:hover, #image-gall-4:hover, #image-gall-5:hover,#image-gall-6:hover, #image-gall-7:hover, #image-gall-8:hover, #image-gall-9:hover, #image-gall-10:hover, #image-gall-11:hover, #image-gall-12:hover, #image-gall-13:hover {opacity: 0.7;}
/* The Modal (background) */
.modal-gallery-fu-sc {
  display: none; /* Hidden by default */
  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(0,0,0); /* Fallback color */
  background-color: rgba(0,0,0,0.9); /* Black w/ opacity */
/* Modal Content (Image) */
.modal-content-gallery-fu-sc {
  margin: auto;
  display: block;
  width: 80%;
  max-width: 700px;
/* Caption of Modal Image (Image Text) - Same Width as the Image */
#caption-gallery-fu-sc {
  margin: auto;
  display: block;
  width: 80%;
  max-width: 700px;
  text-align: center;
  color: #ccc;
  padding: 10px 0;
  height: 150px;
/* Add Animation */
.modal-content-gallery-fu-sc, #caption-gallery-fu-sc {  
  -webkit-animation-name: zoom;
  -webkit-animation-duration: 0.6s;
  animation-name: zoom;
  animation-duration: 0.6s;
@-webkit-keyframes zoom {
  from {-webkit-transform:scale(0)} 
  to {-webkit-transform:scale(1)}
@keyframes zoom {
  from {transform:scale(0)} 
  to {transform:scale(1)}
/* The Close Button */
.close-gallery-fu-sc {
  position: absolute;
  top: 85px;
  right: 35px;
  color: #f1f1f1;
  font-size: 40px;
  font-weight: bold;
  transition: 0.3s;
.close-gallery-fu-sc:focus {
  color: #bbb;
  text-decoration: none;
  cursor: pointer;
/* 100% Image Width on Smaller Screens */
@media only screen and (max-width: 700px){
  .modal-content-gallery-fu-sc {
    width: 100%;
<div class="container">
<!-- The Modal -->
<div id="myModal" class="modal-gallery-fu-sc">
  <!-- The Close Button -->
  <span class="close-gallery-fu-sc">×</span>
  <!-- Modal Content (The Image) -->
  <img class="modal-content-gallery-fu-sc" id="img01">
  <!-- Modal Caption (Image Text) -->
  <div id="caption-gallery-fu-sc"></div>

<!-- Photo Grid -->
<div class="row"> 
  <div class="column">
    <img id="image-gall-1" src="https://www.w3schools.com/w3images/wedding.jpg" alt="wedding" style="width:100%">
    <img id="image-gall-2" src="https://www.w3schools.com/w3images/rocks.jpg" alt="rocks" style="width:100%">
    <img id="image-gall-3" src="https://www.w3schools.com/w3images/falls2.jpg" alt="falls2" style="width:100%">
    <img id="image-gall-4" src="https://www.w3schools.com/w3images/paris.jpg" alt="paris" style="width:100%">
    <img id="image-gall-5" src="https://www.w3schools.com/w3images/nature.jpg" alt="nature" style="width:100%">
    <img id="image-gall-6" src="https://www.w3schools.com/w3images/mist.jpg" alt="mist" style="width:100%">
    <img id="image-gall-7" src="https://www.w3schools.com/w3images/paris.jpg" alt="paris" style="width:100%">
  <div class="column">
    <img id="image-gall-8" src="https://www.w3schools.com/w3images/underwater.jpg" alt="underwater" style="width:100%">
    <img id="image-gall-9" src="https://www.w3schools.com/w3images/ocean.jpg" alt="ocean" style="width:100%">
    <img id="image-gall-10" src="https://www.w3schools.com/w3images/wedding.jpg" alt="wedding" style="width:100%">
    <img id="image-gall-11" src="https://www.w3schools.com/w3images/mountainskies.jpg" alt="" style="width:100%">
    <img id="image-gall-12" src="https://www.w3schools.com/w3images/rocks.jpg" alt="rocks" style="width:100%">
    <img id="image-gall-13" src="https://www.w3schools.com/w3images/underwater.jpg" alt="underwater" style="width:100%">

Source: Ask Javascript Questions