I edited your codepen a bit. So what I done:

  • removed your on click handler
  • added one handler for all clicks
  • applied it only for your images
  • added id for modal-img

I don't recommend you to use multiple ids with the same value. Would be better to use classes instead

// 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("myImg");
var modalImg = document.getElementById("modal-img");
var captionText = document.getElementById("caption");
// img.onclick = function(){
//   modal.style.display = "block";
//   modalImg.src = this.src;
//   captionText.innerHTML = this.alt;
// }


document.addEventListener("click", (e) => {
  const elem = e.target;
  if (elem.id==="myImg") {
    modal.style.display = "block";
    modalImg.src = elem.dataset.biggerSrc || elem.src;
    captionText.innerHTML = elem.alt; 
  }
})

// Get the <span> element that closes the modal
var span = document.getElementsByClassName("close")[0];

// When the user clicks on <span> (x), close the modal
span.onclick = function() { 
  modal.style.display = "none";
}
#myImg {

  border-radius: 5px;
  cursor: pointer;
  transition: 0.3s;
}

#myImg:hover {opacity: 0.7;}


#myImg2 {

  border-radius: 5px;
  cursor: pointer;
  transition: 0.3s;
}

#myImg2:hover {opacity: 0.7;}

/* The Modal (background) */
.modal {
  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 {
  margin: auto;
  display: block;
  width: 80%;
  max-width: 700px;
}

/* Caption of Modal Image */
#caption {
  margin: auto;
  display: block;
  width: 80%;
  max-width: 700px;
  text-align: center;
  color: #ccc;
  padding: 10px 0;
  height: 150px;
}

/* Add Animation */
.modal-content, #caption {  
  -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 {
  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;
}

/* 100% Image Width on Smaller Screens */
@media only screen and (max-width: 700px){
  .modal-content {
    width: 100%;
  }
}
<img style="width:30%" id="myImg" class="img-fluid" src="https://cdn.pixabay.com/photo/2015/04/23/22/00/tree-736885__340.jpg"
data-bigger-src="http://qnimate.com/wp-content/uploads/2014/03/images2.jpg"
>

 <img style="width:28%"  id="myImg" class="img-fluid" src="https://cdn.pixabay.com/photo/2015/06/19/21/24/the-road-815297__340.jpg">
 <img style="width:29%"  id="myImg" class="img-fluid" src="https://image.shutterstock.com/image-photo/mountains-during-sunset-beautiful-natural-260nw-407021107.jpg">

                                                    <!-- The Modal -->
<div id="myModal" class="modal">
  <span class="close">&times;</span>
  <img id="modal-img" class="modal-content"  src="https://encrypted-tbn0.gstatic.com/images?q=tbn%3AANd9GcQS2ol73JZj6-IqypxPZXYS3rRiPwKteoD8vezk9QsRdkjt3jEn&usqp=CAU">
    
  
  <div id="caption"></div>
</div>

Answer from Oleksandr Blyzniuk on Stack Overflow
Top answer
1 of 1
5

I edited your codepen a bit. So what I done:

  • removed your on click handler
  • added one handler for all clicks
  • applied it only for your images
  • added id for modal-img

I don't recommend you to use multiple ids with the same value. Would be better to use classes instead

// 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("myImg");
var modalImg = document.getElementById("modal-img");
var captionText = document.getElementById("caption");
// img.onclick = function(){
//   modal.style.display = "block";
//   modalImg.src = this.src;
//   captionText.innerHTML = this.alt;
// }


document.addEventListener("click", (e) => {
  const elem = e.target;
  if (elem.id==="myImg") {
    modal.style.display = "block";
    modalImg.src = elem.dataset.biggerSrc || elem.src;
    captionText.innerHTML = elem.alt; 
  }
})

// Get the <span> element that closes the modal
var span = document.getElementsByClassName("close")[0];

// When the user clicks on <span> (x), close the modal
span.onclick = function() { 
  modal.style.display = "none";
}
#myImg {

  border-radius: 5px;
  cursor: pointer;
  transition: 0.3s;
}

#myImg:hover {opacity: 0.7;}


#myImg2 {

  border-radius: 5px;
  cursor: pointer;
  transition: 0.3s;
}

#myImg2:hover {opacity: 0.7;}

/* The Modal (background) */
.modal {
  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 {
  margin: auto;
  display: block;
  width: 80%;
  max-width: 700px;
}

/* Caption of Modal Image */
#caption {
  margin: auto;
  display: block;
  width: 80%;
  max-width: 700px;
  text-align: center;
  color: #ccc;
  padding: 10px 0;
  height: 150px;
}

/* Add Animation */
.modal-content, #caption {  
  -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 {
  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;
}

/* 100% Image Width on Smaller Screens */
@media only screen and (max-width: 700px){
  .modal-content {
    width: 100%;
  }
}
<img style="width:30%" id="myImg" class="img-fluid" src="https://cdn.pixabay.com/photo/2015/04/23/22/00/tree-736885__340.jpg"
data-bigger-src="http://qnimate.com/wp-content/uploads/2014/03/images2.jpg"
>

 <img style="width:28%"  id="myImg" class="img-fluid" src="https://cdn.pixabay.com/photo/2015/06/19/21/24/the-road-815297__340.jpg">
 <img style="width:29%"  id="myImg" class="img-fluid" src="https://image.shutterstock.com/image-photo/mountains-during-sunset-beautiful-natural-260nw-407021107.jpg">

                                                    <!-- The Modal -->
<div id="myModal" class="modal">
  <span class="close">&times;</span>
  <img id="modal-img" class="modal-content"  src="https://encrypted-tbn0.gstatic.com/images?q=tbn%3AANd9GcQS2ol73JZj6-IqypxPZXYS3rRiPwKteoD8vezk9QsRdkjt3jEn&usqp=CAU">
    
  
  <div id="caption"></div>
</div>

🌐
W3Schools
w3schools.com › howto › howto_css_modal_images.asp
How To Create Modal Images
Learn how to create responsive Modal Images with CSS and JavaScript. A modal is a dialog box/popup window that is displayed on top of the current page.
Discussions

How set Modal popup multiple image - Stack Overflow
On my site I have some pages that I need to show more image, and if I set this code for other image, the popup work only for the first and not for other images. ... How are you writing the code for multiple images? More on stackoverflow.com
🌐 stackoverflow.com
July 16, 2017
Multiple Modal Pop-ups to show different Images
I'm a noob at coding but I am trying to make a team members' page where their image is clicked on and then another image pops up showing their description etc. I have copied a code from https://www. More on stackoverflow.com
🌐 stackoverflow.com
August 29, 2022
Multiple Images Popup/Modal - CodingForum
I have multiple images that I want to "Click to enlarge" Below is the CSS and HTML code and link to the page. I want to be able to click on each picture to enlarge it and this code only allows the first picture to enlarge. I tried using different myImg codes (myImg2, myImg3) but that didn't work. More on codingforum.net
🌐 codingforum.net
June 4, 2018
How to use bootstrap modal on multiple images on same page on image click?
So why don't you use another plugin ... open a popup ... I am learning English, so I'm not sure if I fully understand but if you want is show different images in a modal by clicking on each thumbnail image. I think that this code can help you. here is an Jsfiddle example: How to show multiple images on ... More on stackoverflow.com
🌐 stackoverflow.com
🌐
Highcharts
highcharts.com › board index › highslide js - the javascript image and media viewer › highslide js usage
Multiple Pop Up Images - Highcharts official support forum
--> <a id="thumb1" href="Images/arkaden_overhead.jpg" class="highslide" onClick="return hs.expand(this)" > <img src="Images/arkaden_overhead.jpg" usemap="#Image-Maps_9201205211949163" style="border: none" alt="" height="180" width="180" /> <map id="_Image-Maps_9201205211949163" name="Image-Maps_9201205211949163"> <area shape="rect" coords="257,370,290,458" href="Images/arkaden_overhead.jpg" alt="Arkaden" title="Arkaden" onclick="return hs.expand(this)" /> <area shape="rect" coords="201,428,234,516" href="Images/arkaden_overhead.jpg" alt="Arkaden" title="Arkaden" onclick="return hs.expand(this)
Top answer
1 of 3
1

Best solution that I have found:

Fisrt, the HTML changes:

Ex: Each image needs their own ID... very minor change to your html... (changes from w3school.com from that original file.

<div class="image"><img **id="myImg2"** src="images/pic02.jpg" alt="" /></div>
<div class="image"><img **id="myImg3"** src="images/pic03.jpg" alt="" /></div>

Original

    <div class="image"><img **id="myImg" src="images/pic01.jpg" alt="" /></div>

Second, CSS changes:

Copy the original "#myImg" and "#myImg:hover" attributes and paste right under .... adding the orinal new (number) after. Each image needs their unique "myImg"and their unique "#myImg:hover"

Ex:

#myImg2 {
    border-radius: 5px;
    cursor: pointer;
    transition: 0.3s;
}

#myImg3 {
    border-radius: 5px;
    cursor: pointer;
    transition: 0.3s;
}

#myImg2:hover {opacity: 0.7;}

#myImg3:hover {opacity: 0.7;}

Original

    #myImg {
        border-radius: 5px;
        cursor: pointer;
        transition: 0.3s;
    }

    #myImg:hover {opacity: 0.7;}

----

Javascript changes: Added the following: Add the var "variables" for each image and the "click" function for each image: --- Ex:

    var img2 = document.getElementById('myImg2');
    var img3 = document.getElementById('myImg3');

    //handle click for myImg2
    img2.onclick = function(){
        modal.style.display = "block";
        modalImg.src = this.src;
        captionText.innerHTML = this.alt;
    }

    //handle click for myImg3
    img3.onclick = function(){
        modal.style.display = "block";
        modalImg.src = this.src;
        captionText.innerHTML = this.alt;
    }

Orginal

<script>
    // 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('myImg');
var modalImg = document.getElementById("img01");
var img2 = document.getElementById('myImg2');
var img3 = document.getElementById('myImg3');
var captionText = document.getElementById("caption");
img.onclick = function(){
    modal.style.display = "block";
    modalImg.src = this.src;
    captionText.innerHTML = this.alt;
}

//handle click for myImg2
img2.onclick = function(){
    modal.style.display = "block";
    modalImg.src = this.src;
    captionText.innerHTML = this.alt;
}

//handle click for myImg3
img3.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")[0];

// When the user clicks on <span> (x), close the modal
span.onclick = function() { 
  modal.style.display = "none";
}
    </script>

Here is an example of something very easy to understand:

<!DOCTYPE html>
<html>
<head>
<style>
#myImg {
    border-radius: 5px;
    cursor: pointer;
    transition: 0.3s;
}

#myImg2 {
    border-radius: 5px;
    cursor: pointer;
    transition: 0.3s;
}

#myImg3 {
    border-radius: 5px;
    cursor: pointer;
    transition: 0.3s;
}

#myImg:hover {opacity: 0.7;}

#myImg2:hover {opacity: 0.7;}

#myImg3:hover {opacity: 0.7;}

/* The Modal (background) */
.modal {
    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 {
    margin: auto;
    display: block;
    width: 80%;
    max-width: 700px;
}

/* Caption of Modal Image */
#caption {
    margin: auto;
    display: block;
    width: 80%;
    max-width: 700px;
    text-align: center;
    color: #ccc;
    padding: 10px 0;
    height: 150px;
}

/* Add Animation */
.modal-content, #caption {    
    -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 {
    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;
}

/* 100% Image Width on Smaller Screens */
@media only screen and (max-width: 700px){
    .modal-content {
        width: 100%;
    }
}
</style>
</head>
<body>

<h2>Image Modal</h2>
<p>Guitarfetish.com </p>
<p>Gallery ideas</p>

<img id="myImg" src="img01.jpg" alt="XGP Tele Bodies" width="600" height="200">

<!-- The Modal -->
<div id="myModal" class="modal">
  <span class="close">&times;</span>
  <img class="modal-content" id="img01">
  <div id="caption"></div>
</div>

<img id="myImg2" src="img02.jpg" alt="Xaviere Guitars" width="600" height="200">

<img id="myImg3" src="img03.jpg" alt="Premium Guitar Cases" width="600" height="200">
<script>
// 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('myImg');
var img2 = document.getElementById('myImg2');
var img3 = document.getElementById('myImg3');
var modalImg = document.getElementById("img01");
var captionText = document.getElementById("caption");
img.onclick = function(){
    modal.style.display = "block";
    modalImg.src = this.src;
    captionText.innerHTML = this.alt;
}

//handle click for myImg2
img2.onclick = function(){
    modal.style.display = "block";
    modalImg.src = this.src;
    captionText.innerHTML = this.alt;
}

//handle click for myImg3
img3.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")[0];

// When the user clicks on <span> (x), close the modal
span.onclick = function() { 
    modal.style.display = "none";
}
</script>

</body>
</html>
2 of 3
0

This implementation will not work as you are referring to the same DOM element by ID. You can try this JSFiddle which uses magnific popup plugin to make a multiple image modal. This would be easier for you to implement as well.

Here is an example of magnific popup: https://jsfiddle.net/8f60f93t/2/

🌐
Stack Overflow
stackoverflow.com › questions › 73528818 › multiple-modal-pop-ups-to-show-different-images
Multiple Modal Pop-ups to show different Images
August 29, 2022 - You are using same id on both images. I used custom function img_click and passed the clicked element with it like this onClick="img_click(this)" and now your both images clicks are working fine and showing alts saved on those images.
🌐
CodingForum
codingforum.net › home › client side development › html & css
Multiple Images Popup/Modal - CodingForum
June 4, 2018 - for (var i = 0, gallery, anchors; gallery = galleries[i]; i++) { if (anchors = gallery.getElementsByTagName('a')) { for (var j = 0, anchor; anchor = anchors[j]; j++) { anchor.addEventListener('click', modalImageOpen, false); } } } For opening the image I would create the IMG dom element on the fly so we can trap onload -- this way rather than having the user sit there watching the image load old-school, we can show a loading animation instead.
Find elsewhere
Top answer
1 of 4
18

You are very close to your goal, you have 2 images

<img height="100" width="80" id="1" data-toggle="modal" data-target="#myModal" src='http://tympanus.net/Tutorials/CaptionHoverEffects/images/1.png' alt='Text dollar code part one.' />
<img height="100" width="80" id="2" data-toggle="modal" data-target="#myModal" src='http://tympanus.net/Tutorials/CaptionHoverEffects/images/2.png' alt='Text dollar code part one.' />

One Modal

<div id="myModal" class="modal fade" role="dialog">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-body">
                <img class="img-responsive" src="" />
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
            </div>
        </div>
    </div>
</div>

If you want to show image in modal with your approach using click function

$(document).ready(function () {
    $('img').on('click', function () {
        var image = $(this).attr('src');
        $('#myModal').on('show.bs.modal', function () {
            $(".img-responsive").attr("src", image);
        });
    });
});

Fiddle


Or you can use bootstrap modal event function only, less complicated and better approach (recommended solution)

$(document).ready(function () {
        $('#myModal').on('show.bs.modal', function (e) {
            var image = $(e.relatedTarget).attr('src');
            $(".img-responsive").attr("src", image);
        });
});

Fiddle

2 of 4
1

You mean you have 18 images, when you click on a image , website will open a open to show a larger image?

So why don't you use another plugin such as Nivo lightbox, which allow you open a popup to show image, and even though put all your image in a gallery when open a popup

🌐
Unc
opal.ils.unc.edu › ~lblakej › website-helps › 04-image-popup
Image Popup Example
Click image to popup the larger image with the alt text as the caption. Adapted from this example at W3 Schools. Popups are often called a "Modal." To see the code and instructions on the steps you need to take to get this to work, right-click and view page source.
🌐
CodePen
codepen.io › r3dg3cko › pen › ZLryQG
multi image modal - CSS and JS
If active, Pens will autosave every 30 seconds after being saved once. If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update. If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting. ... Visit your global Editor Settings. ... <div class="container1"> <img src="https://images-na.ssl-images-amazon.com/images/M/MV5BMTczNTI2ODUwOF5BMl5BanBnXkFtZTcwMTU0NTIzMw@@._V1_SY1000_CR0,0,674,1000_AL_.jpg" style="max-width:100%;cursor:pointer" onclick="onClick(this)" class="modal-hover-o
🌐
ASPSnippets
aspsnippets.com › questions › 895083 › Display-multiple-images-in-Bootstrap-Modal-Popup-using-jQuery
Display multiple images in Bootstrap Modal Popup using jQuery
September 24, 2018 - <script type="text/javascript" src='https://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.8.3.min.js'></script> <script type="text/javascript" src='https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.0.3/js/bootstrap.min.js'></script> <link rel="stylesheet" href='https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.0.3/css/bootstrap.min.css' media="screen" /> <script type="text/javascript"> $(function () { $("#btnShowPopup").click(function () { $("#MyPopup").modal("show"); }); }); </script> <div> <!-- Bootstrap --> <center> <input type="button" id="btnShowPopup" value="Show Popup" class
🌐
Cloudinary
cloudinary.com › home › mastering javascript image popup
Mastering JavaScript Image Popup | Cloudinary
January 14, 2026 - Finally, an event listener (click event) is added to each image container <div>, which, when clicked, sets the modal element’s display style to “block” to show it, changes modalImg‘s src attribute to the clicked image’s URL and finally changes the captionText‘s inner HTML to the clicked image’s title. With the loadImages function now complete, we retrieve references to the modal (modal), image (modalImg), caption (captionText), and close button (span). We then add an onlick function to the span, which, when clicked, sets the modal’s display style is set to "none" to hide it.
🌐
GitHub
github.com › dimsemenov › Magnific-Popup › issues › 351
Single popup with multiple images · Issue #351
January 27, 2014 - Would it be possible to build a single popup with a gallery inside and some content below? The content would be the same, only the the images would change as you click on the navigation arrows.
Author   Macxim
Top answer
1 of 2
1

The span elements should be completely removed and its classes placed on the image elements themselves.

Also, you have a nested section element that isn't doing anything for you.

Lastly, do not use HTML heading elements (<h1>...<h6>) because of the way they style the text. Formatting is the job of CSS. Instead of headings, it is more appropriate to surround each image and its accompanying text with figure and figcaption elements.

img { 
  width:200px;
  border:1px solid black; /* This is only added for testing purposes*/
}

.thumbnail:hover {
   width: 500px;
   height:auto;
   position:relative;
   /* push image to the right by 1/2 the screen width and 1/2 the image width */
   margin-left:calc(50% - 250px);
}
<section id="main">
  <div class="inner">
    <div class="box alt">
      <div class="row 50% uniform">
         <div class="4u">
           <figure>
             <img src="https://pbs.twimg.com/profile_images/562466745340817408/_nIu8KHX.jpeg" alt="" class="thumbnail">
             <figcaption>Marble</figcaption>
           </figure>
         </div>

         <div class="4u">
           <figure>
             <img src="http://www.critterbabies.com/wp-content/gallery/kittens/cats-animals-kittens-background-us.jpg" alt="" class="thumbnail">
             <figcaption>Marble</figcaption>
           </figure>
         </div>
         
         <div class="4u">
           <figure>
             <img src="http://www.warrenphotographic.co.uk/photography/bigs/08482-Fluffy-ginger-female-kitten.jpg" alt="" class="thumbnail">
             <figcaption>Marble</figcaption>
           </figure>
         </div>
         
       </div>
     </div>
   </div>
 </section>

2 of 2
1

I've taken Scott Marcus' answer and adapted to click, which was your original request.

The main diffence is the addition of a tags targeting elements on the page and using :target in the css.

img { 
  width:200px;
  border:1px solid black; /* This is only added for testing purposes*/
}

.thumbnail:target {
   width: 500px;
   height:auto;
   position:relative;
   /* push image to the right by 1/2 the screen width and 1/2 the image width */
   margin-left:calc(50% - 250px);
}
<section id="main">
  <div class="inner">
    <div class="box alt">
      <div class="row 50% uniform">
         <div class="4u">
           <figure>
             <a href="#image1">
             <img src="https://pbs.twimg.com/profile_images/562466745340817408/_nIu8KHX.jpeg" alt="" class="thumbnail" id="image1">
             </a>
             <figcaption>Marble</figcaption>
           </figure>
         </div>

         <div class="4u">
           <figure>
             <a href="#image2">
             <img src="http://www.critterbabies.com/wp-content/gallery/kittens/cats-animals-kittens-background-us.jpg" alt="" class="thumbnail" id="image2">
             </a>
             <figcaption>Marble</figcaption>
           </figure>
         </div>
         
         <div class="4u">
           <figure>
             <a href="#image3">
             <img src="http://www.warrenphotographic.co.uk/photography/bigs/08482-Fluffy-ginger-female-kitten.jpg" alt="" class="thumbnail" id="image3">
             </a>
             <figcaption>Marble</figcaption>
           </figure>
         </div>
         
       </div>
     </div>
   </div>
 </section>

🌐
Stack Overflow
stackoverflow.com › questions › 60938312 › how-to-add-popup-with-different-image-to-show
How to add popup with different image to show?
The javascript code is tied to the ID of your image. var modal = document.getElementById("myModal"); What you could do is for each <img> tag you can include the extra data that you need (e.g. caption) as a data field for the tag like: <img data-caption="somevalue"> Then you can use the function to edit the modal (maximized panel) by populating the correct information for the clicked image.
🌐
HubSpot
community.hubspot.com › t5 › Blog-Website-Page-Publishing › Need-to-create-a-popup-on-click-of-an-image › m-p › 810418
Solved: HubSpot Community - Re: Need to create a popup on click of an image - HubSpot Community
July 4, 2023 - Hi , if you have a developer by your side or are not afraid of using the design-manager/design-tools you could create a custom module for pop-ups. It's a little bit tricky but also not the hardest thing you can create. Here's a step-by-step guide how to create a custom pop-up module Open the d...
🌐
CodePen
codepen.io › bluminethemes › pen › reEJZa
Magnific Popup - Open custom gallery on button click
<h3>Magnific Popup - Open custom gallery on button click</h3> <ul> <li> <a href="#gallery-1" class="btn-gallery">Gallery 1</a> </li> <li> <a href="#gallery-2" class="btn-gallery">Gallery 2</a> </li> <li> <a href="#gallery-3" class="btn-gall...
🌐
Reddit
reddit.com › r/wordpress › click image > popup with text on and link to another url
r/Wordpress on Reddit: Click image > popup with text on and link to another url
August 20, 2023 -

Hello,

Still learning everything wordpress has to offer. Just want to start out by saying I have bought Elementor pro and have been using that for most of the build.

I am looking for something specific and not sure where to look or what it would be called. On my page I will have 8 images in 2 columns. I want the images to have some text on top and then when you click on the image, a pop up comes on screen that has more text and a link to an external site.

If anyone can point me in the right direction I would appreciate any help I can get.

Top answer
1 of 2
2
Add an Image Gallery Widget: Inside the section, add an "Image Gallery" widget. This widget will allow you to create a grid of images. Configure the Image Gallery: Configure the settings of the Image Gallery widget to display your 8 images in 2 columns. You can adjust the number of columns and other layout settings as needed. Add Overlay Content: For each image in the gallery, you'll need to create overlay content that will be displayed when the image is clicked. a. Click on an image in the Image Gallery widget to edit it. b. In the "Content" tab, you can add the text you want to display on top of the image as overlay content. Create a Popup: To create the pop-up that appears when an image is clicked, follow these steps: a. Click on the image in the Image Gallery widget. b. In the "Link" tab, choose "Custom URL" and enter a hashtag (#) followed by a unique identifier for this pop-up (e.g., #popup-1). c. In the same "Link" tab, enable the "Open in Lightbox" option. Add Pop-Up Content: Create a new section in Elementor for the pop-up content. This section will contain the additional text and link to an external site. a. Add a new section. b. Inside the section, add a "Text Editor" widget to display the additional text. c. Below the text, you can add a "Button" widget to link to an external site. Configure the button's settings, including the link URL. Associate Pop-Up with Overlay: To associate the pop-up content with the overlay, follow these steps: a. Click on the pop-up link in the Image Gallery widget. b. In the "Link" tab, set the "On Click" option to "Open Popup". c. Select the pop-up you've created from the dropdown list.
2 of 2
1
You can achieve this with Poper —a simple popup builder that lets you trigger popups when clicking an image. You can add text inside the popup and link it to an external site. It also supports embeds if you prefer inline content instead. Since you have Elementor Pro, its popup builder is an option too, but Poper is more lightweight and focused on popups. I’m the creator of Poper, so if you need any help, feel free to ask! 🚀