@isaac-svg
Posted
To close the modal when you click outside, add an event listener on the parent element and check if the element click contains the class class you gave to the parent. If it contains that class then you remove the class that shows the modal
EXAMPLE CODE
const removeModal = (e) => {
if (e.target.classList.contains("modal")) {
e.target.classList.remove("modal");
}
if (e.target.classList.contains("modal-close")) {
imagesContainer.classList.remove("modal");
}
};
END OF CODE
So you have to invoke this function anytime a user clicks on an element you desire that it closes a modal . You can keep on with the conditionals.
Marked as helpful