img.onclick = function() {
modal.style.display = "block";
modalImg.src = this.src;
captionText.innerHTML = this.alt;
}
When an image is clicked, a modal’s display
will be set to block
the modal image’s src
will be set to the image’s src
and the caption text will be set to the alt text of the image.
I’ve edited your post for readability. When you enter a code block into the forum, remember to precede it with a line of three backticks and follow it with a line of three backticks to make easier to read. See this post to find the backtick on your keyboard. The “preformatted text” tool in the editor (</>
) will also add backticks around text.
Can you show us an example of your code? My guess is that the modal’s display is normally none
. When the image is clicked, the display of the modal is then switched to block
, which then shows the user the modal.