4

So, I want to remove an input element before user submit the form. I know JS normally is synchronous, but there are situation that it could act asynchronous.

My question is, is my code guarantee to remove the input element before submit? Thank you!

form.addEventListener("submit",removeElement(e));

function removeElement(e){
    return function(){
        e.remove();
    }
}
zeruitle
  • 63
  • 1
  • 6
  • I'm tempted to close this as a duplicate of http://stackoverflow.com/q/21607692/497418 because it explains how the event loop works in JavaScript, which is essentially what you're asking. – zzzzBov May 31 '16 at 18:40
  • Both yes and no. The `submit` event handler is guaranteed to fire before the form submits, but there's no guarantee the browser supports `node.remove()` – adeneo May 31 '16 at 18:41
  • Some older versions of IE don't even support `addEventListener` – jeffjenx May 31 '16 at 18:45

0 Answers0