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 text = document.getElementById("content").value;
  copyTextToClipboard(text);
}

async function copyTextToClipboard(text) {
  try {
    await navigator.clipboard.writeText(text);
    console.log('Text copied to clipboard');
  } catch (err) {
    console.error('Error in copying text: ', err);
  }
}