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

221
Views
How to determine ordering of event listeners in Javascript

I'm confused by the ordering of event listeners in Javascript. If I have a form with a submit button and I'd like to alert a user instead of automatically submitting the form, but only when the submit using the Enter key, I can create an event listener for an Enter keypress, event.preventDefault(), etc.

Why is it that the default onsubmit event listener for the form is not triggered first?

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

0

Events do follow the law of causality. Smaller primitives build up larger, more important ones:

  • keydown -> keyup -> keypress -> change
  • mousedown -> mouseup -> click -> submit

In your case, the Enter keypress event causes the submit event.

Preventing the default action of an event will suppress the ensuing ones. They can't happen in reverse.

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!