In Javascript, how can I attach an event handler so that it gets run after the default action?
<form target="_blank" action="submit.php" onsubmit="doThisAfterSubmit()">
<input type="submit" onclick="doThisAfterSubmit()" />
</form>
Similar but insufficient Stack Overflow questions:
javascript: Possible to add event handler that runs after the default behavior?
How to catch event after default action was performed in JavaScript
I have read these but they are dealing with keystroke events solved with using a variation such as keyup
over keypress
. The only other solution I have seen is the setTimeout()
method. I want to avoid using setTimeout()
in favor of a more elegant solution if one exists.
My use case is that I want to remove the form from the DOM after the submit.