Admin
< /code>
Я хочу, чтобы, когда вы нажимаете на карту, отображается модальный.var infomodal = document.getElementById("info-modal");
// Get the button that opens the modal
var infobtn = document.getElementsByClassName("Info-btn")[0];
// Get the element that closes the modal
var infospan = document.getElementsByClassName("infoclose")[0];
// When the user clicks the button, open the modal
infobtn.addEventListener("click", function(){
infomodal.style.display = "block";
})
// When the user clicks on (x), close the modal
infospan.addEventListener("click", function(){
infomodal.style.display = "none";
})
// When the user clicks anywhere outside of the modal, close it
window.addEventListener("click", function(event){
if (event.target == infomodal) {
infomodal.style.display = "none";
}
})
работает, но только первая карта способна отображать свою модальную, а не другие карты.
Как я могу использовать getelementsbyclassname ? У меня есть много карт, подобных этим: < /p> [code]
Admin
< /code> Я хочу, чтобы, когда вы нажимаете на карту, отображается модальный.var infomodal = document.getElementById("info-modal");
// Get the button that opens the modal var infobtn = document.getElementsByClassName("Info-btn")[0];
// Get the element that closes the modal var infospan = document.getElementsByClassName("infoclose")[0];
// When the user clicks the button, open the modal infobtn.addEventListener("click", function(){ infomodal.style.display = "block"; })
// When the user clicks on (x), close the modal infospan.addEventListener("click", function(){ infomodal.style.display = "none"; })
// When the user clicks anywhere outside of the modal, close it window.addEventListener("click", function(event){ if (event.target == infomodal) { infomodal.style.display = "none"; } }) [/code] работает, но только первая карта способна отображать свою модальную, а не другие карты.