JSFiddle - React, Tailwind, and code Playground

by sfoster

HTML

<form>
  <p>Name: <input type="text" id="uname"></p>
  <p>Password: <input type="password"></p>
</form>
<button onclick="sendDataAndRemoveForm()">
  Fetch and remove form
</button>
<button onclick="removeForm()">
  Just remove form
</button>

JavaScript

async function sendDataAndRemoveForm() {
  console.log("performing fetch");
  await fetch(location.pathname);
  let f = document.querySelector("form");
  removeForm();
}
async function removeForm() {
  let f = document.querySelector("form");
  console.log("removing form");
  f.parentNode.removeChild(f);
}