JSFiddle - React, Tailwind, and code Playground

by techiedelight

HTML

<body>
  <textarea id="content" rows="5" cols="30">Write something here...</textarea>
  <button id="copy" title="Copy Textarea Content">Copy</button>
</body>

JavaScript

document.getElementById("copy").onclick = function() {
  var copyTextarea = document.createElement("textarea");
  copyTextarea.style.position = "fixed";
  copyTextarea.style.opacity = "0";
  copyTextarea.textContent = document.getElementById("content").value;

  document.body.appendChild(copyTextarea);
  copyTextarea.select();
  document.execCommand("copy");
  document.body.removeChild(copyTextarea);
}