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

190
Views
Close the alert div only after clicking the X button a number of times
<div class="alert">
    <span 
        id="button" 
        class="closebtn" 
        onclick="this.parentElement.style.display='none';">&times;
    </span>
    This is an alert box.
</div>

I tried using the alert function but I learned that you can't manipulate it so I created an alert div but I don't know how to achieve the title.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can store number of clicks in a variable and when it reaches certain limit, you hide the alert and reset the counter.

let countClicks = 0;

document.querySelector('#button').onclick = function() {
    countClicks++;
  
  if (countClicks === 3) {
    document.querySelector('.alert').classList.add('hidden');
    countClicks = 0;
  }
};
.hidden {
  display: none;
}

#button {
  cursor: pointer;
}
<div class="alert">
  <span>This is an alert box.</span>
  <span id="button" class="closebtn" role="button">&times;</span>      
</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!