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?
Events do follow the law of causality. Smaller primitives build up larger, more important ones:
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.