0

I am trying to figure out how to use the same function
(closing a modal when clicking out of the modalbox):

window.onclick = function(event) {
if (event.target == modalEth) {
    modalEth.style.display = "none";
}

and

window.onclick = function(event) {
if (event.target == modalBtc) {
    modalBtc.style.display = "none";
}

within to different modals.

Right now, only the onclick funktion "modalBtc" works the way it should.

I don't have a clue how to bring the first function "modalEth" to life.

It would be great if someone could help me out with a solution.


HTML (1. ModalEth, 2. ModalBtc)

<div id="myModalEth" class="modalEth">
<div class="modal-contentEth">
<p>some content</p>
</div>
</div>

<div id="myModalBtc" class="modalBtc">
<div class="modal-contentBtc">
<p>some content</p>
</div>
</div>

1 Answers1

0
document.getElementById('myModalEth').addEventListener('click', function(event) {
    this.style.display = "none";
}
document.getElementById('myModalBtc').addEventListener('click', function(event) {
    this.style.display = "none";
}

This hides the modal when the user clicks inside the modal.

Coli
  • 927
  • 8
  • 28