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

215
Views
my close button does not work on my popup modal

As the title stated, Ive created this delayed popup modal on my page and it is all fine, the only problem is that my close button isn't working, hovering over it will trigger the css, but clicking it won't cause it to close. I assume my javascript has something to do with the error, but I could not find the solution to fix it.

HTML:

                 <div id="delayedpopupmodal">
                            <button  id="close">&times;</button>
                            <h2>Want to enquire us further?</h2>
                            
                            
                            <h4>
                            Contact Us: <a href="mailto:randommail@email.com"> Email Us!</a></h4>
                        </div>
                        
                </div>
            </div>

CSS:

.delayedpopupmodal{
    background-color: black;
    color:white;
    width: 450px;
    padding: 30px 40px;
    position: absolute;
    transform: translate(-50%, -50%);
    left: 50%;
    top: 50%;
    border-radius: 10px;
    display: none;
}

.delayedpopupmodal button{
    display: block;
    margin: 0 0 20px auto;
    background-color: transparent;
    font-size: 40px;
    color: white;
    border: none;
    outline: none;
}

.delayedpopupmodal button:hover {
    display: block;
    margin: 0 0 20px auto;
    background-color: transparent;
    font-size: 40px;
    color: red;
    border: 5px;
    outline-color: red;
}

h4{
    color:white;
    text-align: center;
}

JS:

window.addEventListener("load", function(){
    setTimeout(
        function open(event){
            document.querySelector(".delayedpopupmodal").style.display = "block";
        },
        1000
    )
});

document.querySelector("#close").addEventListener("click",function(){
    document.querySelector(".delayedpopupmodal").style.display = "none";
})
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

delayedpopupmodal is id not class , so change .delayedpopupmodal to #delayedpopupmodal :

const modal = document.querySelector("#delayedpopupmodal")
window.addEventListener("load", function(){
    setTimeout(
        function open(event){
            modal.style.display = "block";
        },
        1000
    )
});

document.querySelector("#close").addEventListener("click",function(){
    modal.style.display = "none";
})
#delayedpopupmodal{
    background-color: black;
    color:white;
    width: 450px;
    padding: 30px 40px;
    position: absolute;
    transform: translate(-50%, -50%);
    left: 50%;
    top: 50%;
    border-radius: 10px;
    display: none;
}

#delayedpopupmodal button{
    display: block;
    margin: 0 0 20px auto;
    background-color: transparent;
    font-size: 40px;
    color: white;
    border: none;
    outline: none;
}

#delayedpopupmodal button:hover {
    display: block;
    margin: 0 0 20px auto;
    background-color: transparent;
    font-size: 40px;
    color: red;
    border: 5px;
    outline-color: red;
}

h4{
    color:white;
    text-align: center;
}
<div id="delayedpopupmodal">
  <button  id="close">&times;</button>
  <h2>Want to enquire us further?</h2>
  <h4>Contact Us: <a href="mailto:randommail@email.com"> Email Us!</a></h4>
</div>

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!