I'm currently trying to set up a gallery in Bootstrap 4. Now I want the images to be clickable and open a larger version. This works great, but as soon as I use more than one Script, it will no longer allow me to close modals.
Here is my code:
<div id="Modal01" class="modal">
<span class="close">×</span>
<img class="modal-content" id="img01">
</div>
<div class="col-md-3">
<div class="thumbnail">
<img id="TheImage" src="/img/galleryimg1.png">
</div>
</div>
JS:
<script>
var modal = document.getElementById('Modal01');
var img = document.getElementById('TheImage');
var modalImg = document.getElementById("img01");
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";
}
</script>
Hope you guys can help me.
source
share