0
const btnMail = document.querySelector("#mail-button")
const popupForm = document.querySelector("#popup-Form")
const btnCancel = document.querySelector("#btn_cancel")

const openform = () => {
    btnMail.addEventListener('click', () => {
        popupForm.style.display="block"
    })
}
openform()

const closeform = () => {
    btnCancel.addEventListener('click', (e) => {
        e.preventDefault()
        popupForm.style.display="none"
    })
}
closeform()

Hi, I made two functions to open the form popup with one button and close it with another button I want to make a new function when the user click outside the form popup for close the form popup, I tried the method target but it didn't work. What javascript method can I use to achieve this? Thanks you

Fradé
  • 195
  • 1
  • 2
  • 9
  • Please read [How do I ask a good question?](https://stackoverflow.com/help/how-to-ask) and [How to create a Minimal, Reproducible Example](https://stackoverflow.com/help/minimal-reproducible-example) – Rojo Mar 26 '21 at 14:17
  • Additionally first ***>>>[Search for related topics on SO](https://www.google.com/search?q=javascript+close+clicking+outside+site:stackoverflow.com)<<<*** and if you get stuck, post a [mcve] of your attempt, noting input and expected output using the [`[<>]`](https://meta.stackoverflow.com/questions/358992/ive-been-told-to-create-a-runnable-example-with-stack-snippets-how-do-i-do) snippet editor. – mplungjan Mar 26 '21 at 14:19

0 Answers0