i need to have multiple image modals with different bodies. Each image would have a separate description that shows up when its clicked. I've only found other answers that display each images alt but I need it to display other text when its clicked. I have it right now where i have multiple image modals but each one opens the same caption.
The javascript
function onClick(element) {
document.getElementById("modal01").style.display = "block";
}
The html
<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-opacity">
</div>
<div class="container1">
<img src="https://images-na.ssl-images-amazon.com/images/M/MV5BMTUyNzk3MjA1OF5BMl5BanBnXkFtZTcwMTE1Njg2MQ@@._V1_SY1000_CR0,0,674,1000_AL_.jpg" style="max-width:100%;cursor:pointer"
onclick="onClick(this)" class="modal-hover-opacity">
</div>
<div class="container1">
<img src="https://images-na.ssl-images-amazon.com/images/M/MV5BMTM0MDgwNjMyMl5BMl5BanBnXkFtZTcwNTg3NzAzMw@@._V1_.jpg" style="max-width:100%;cursor:pointer"
onclick="onClick(this)" class="modal-hover-opacity">
</div>
<div id="modal01" class="modal" onclick="this.style.display='none'">
<span class="close">× </span>
<div class="modal-content">
<img id="img01" style="max-width:100%">
<div id="caption" style="color:white">This is the caption</div>
<div id="2ndcaption" style="color:white">this is the 2nd</div>
<div id="3rdcaption" style="color:white">This is the 3rd</div>
</div>
</div>
and the CSS
.modal {
z-index:1;
display:none;
padding-top:10px;
position:fixed;
left:0;
top:0;
width:100%;
height:100%;
overflow:auto;
background-color:rgb(0,0,0);
background-color:rgba(0,0,0,0.8)
}
.modal-content{
margin: auto;
display: block;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
.modal-hover-opacity {
opacity:1;
filter:alpha(opacity=100);
-webkit-backface-visibility:hidden
}
.modal-hover-opacity:hover {
opacity:0.60;
filter:alpha(opacity=60);
-webkit-backface-visibility:hidden
}
.close {
text-decoration:none;float:right;font-size:24px;font-weight:bold;color:white
}
.container1 {
width:200px;
display:inline-block;
}
.modal-content, #caption {
-webkit-animation-name: zoom;
-webkit-animation-duration: 0.6s;
animation-name: zoom;
animation-duration: 0.6s;
}