While this works:
var lnk = document.getElementById("lnk");
lnk.onclick = function() {
modal.style.display = "block";
}
it no longer works with class and getElementsByClassName
While this works:
var lnk = document.getElementById("lnk");
lnk.onclick = function() {
modal.style.display = "block";
}
it no longer works with class and getElementsByClassName
getElementsByClassName
returns a nodeList
which is array like.
So you would have to bind the event to each node
in the list.
var lnks = document.getElementsByClassName("lnk");
or
var lnks = document.querySelectorAll(".lnk");
lnks.forEach(function(elem) {
elem.onclick = function() {
modal.style.display = "block";
}
});