Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

81
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!