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

157
Views
JavaScript button click not executing fast enough

Look following example. Click on reset button, you will get console log 1 so you can confirm its working.

When you click search field, it will expand, making buttons float to new line (including reset button). Now if you try to click reset button while its in new line, the transition which closes search field will execute faster than the click on the reset button. Not a major problem but intriguing. Is this expected behavior?

document.querySelector(".reset").addEventListener("click", function(e) {
  console.log(1)
});
.wrap {
  max-width: 700px;
}

.a {
  padding: 10px 50px;
  background: #ccc;
  display: inline-flex;
}

.filter {
  width: 50px;
  transition: all 0.1s;
}

.filter:focus {
  width: 250px;
}
<div class="wrap">
  <input type="search" class="filter">
  <div class="a">button 1</div>
  <div class="a">button 2 </div>
  <div class="a">button 3</div>
  <div class="a reset">reset</div>
</div>

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

0

I think the issue is that the blur event is firing before the click event occurs, to remedy this you can use the mousedown event which fires before blur:

document.querySelector(".reset").addEventListener("mousedown", function(e) {
  console.log(1)
});
about 4 years ago · Juan Pablo Isaza Report

0

onclick requires the events onmousedown and onmouseup to be concurrent.

In your case, they are separated by the focusout event, and so onclick doesn't fire.

https://w3c.github.io/uievents/#click

Depending upon the environment configuration, the click event MAY be dispatched if one or more of the event types mouseover, mousemove, and mouseout occur between the press and release of the pointing device button.

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!