Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

84
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda