I came across a simple lightbox code snippet, but it's based on IDs and I plan to use it for more than 20 items. I don't want to manually write out 20 JavaScript lines when there could be a more efficient way to handle it dynamically. My JS skills are not advanced enough to streamline this process.
HTML:
<template id="one">
<h1>Using HTML <template one> Tag</h1>
<p>The template element contains HTML code without displaying it.<br>Not supported in older browsers.</p>
</template>
<button class="template" data-ref="one">template</button>
<template id="two">
<h1>Utilizing HTML <template two> Tag</h1>
<p>The template element holds HTML code without displaying it.<br>Doesn't work in older browsers.</p>
</template>
<button class="template" data-ref="two">second template</button>
JS:
const templateInstance = basicLightbox.create(document.querySelector('#one'))
const templateInstanceTwo = basicLightbox.create(document.querySelector('#two'))
document.querySelector('button.template' + '[data-ref=one]').onclick = templateInstance.show
document.querySelector('button.template' + '[data-ref=two]').onclick = templateInstanceTwo.show
While this setup does function, it lacks scalability when dealing with a large number of templates.