Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

85
Visualizações
Closing Modal box in Javascript

I am trying out Modal boxes in my project and I came upon a problem, that I am unable to close the modal box when a click is made outside of the Modal box. I tried the following code, but this closes the modal box at the same instant it is opened. I tried using setTimeout method too. Its not working. Could anyone help me out with this?

const gstModal=()=>{
    g=document.getElementsByClassName("modal-gst")[0];
    g.style.display="block";
    document.addEventListener('click', function(event) {
        var isClickInside = g.contains(event.target);
        if (!isClickInside) {
            closeGST();
        }
      });
}

function closeGST(){
    document.getElementsByClassName("modal-gst")[0].style.display="none";
}
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

If you have an overlay div along with the popup then you can handle the click easily on the overlay div click. Here is a sample modal popup by using HTML & JS

https://www.w3schools.com/howto/howto_css_modals.asp

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda