Wondering if you someone could help.
I am using https://micromodal.vercel.app/ as a modal window/popup. Need to pass the data-value of the button into the modal window so I can do show what was clicked.
Below works however, not the first time, if I close the modal window and open it again then it shows the 'data-name' and 'data-value'. There is probably an easier way, hoping someone can assist. Thanks.
<a data-name="One" data-url="https://www.google.com" data-micromodal-trigger="modal-1" class="btn">One</a>
<a data-name="Two" data-url="https://www.yahoo.com" data-micromodal-trigger="modal-1" class="btn">Two</a>
<a data-name="Three" data-url="https://www.bing.com" data-micromodal-trigger="modal-1" class="btn">Three</a>
MicroModal.init({
onShow: function() {
const allButtons = document.querySelectorAll(".btn");
allButtons.forEach(function (button) {
button.addEventListener("click", () => {
console.log(button.getAttribute('data-name'))
console.log(button.getAttribute('data-url'))
});
});
},
});