()
| 4 | const modalBody = modal.querySelector(".body"); |
| 5 | |
| 6 | function initModal() { |
| 7 | // When the user clicks on <span> (x), close the modal |
| 8 | closeModalBtn.onclick = function () { |
| 9 | toggleModal(false); |
| 10 | }; |
| 11 | |
| 12 | // When the user clicks anywhere outside of the modal, close it |
| 13 | window.addEventListener("click", function (event) { |
| 14 | if (event.target == modal) { |
| 15 | toggleModal(false); |
| 16 | } |
| 17 | }); |
| 18 | } |
| 19 | |
| 20 | export function toggleModal(show = true) { |
| 21 | modal.classList.toggle("hide", !show); |