How to modify javascript for multiple instances of an image gallery

I discovered this image modal on w3schools and I would like to modify the javascript so that i can have multiple images. My javascript knowledge is limited so any help will be greatly appreciated. Here is the link to the modal image gallery. https://www.w3schools.com/howto/howto_css_modal_images.asp

I thought that adding the following code and changing the variable name would be all that i needed to do but I was wrong. It

var img2 = document.getElementById('myImg');
var modalImg2 = document.getElementById("img01");
var captionText2 = document.getElementById("caption");
img.onclick = function(){
    modal.style.display = "block";
    modalImg.src = this.src;
    captionText.innerHTML = this.alt;
}

Do you want to change the images with carousel option or insert all the images in the modal window?

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.