Using dialog elements for a lightbox

I thought I would try using <dialog> elements to create a light box. I’m almost there (I think) but I’m not sure how to get the matching dialog to open when I click the appropriate image.

This is my codepen

Does this work?

img.forEach((element, index) => element.addEventListener("click", function () {d[index].showModal();}));

2 Likes

I came up with the same and it appears to work

2 Likes

Thank you, gents :slight_smile:

1 Like