JSFiddle - React, Tailwind, and code Playground
by abuhamzah
HTML
<div id="myhtml">
<p>public class TestAccountTrigger { </p><p></p>
<p>@testSetup</p><p>static void initData(){</p><p>Account a0 = new
Account(Name = 'Account Zero');</p><p>insert a0; </p><p> }</p>
</div>
<button type="button" onclick="copyText()">Copy</button>
JavaScript
function copyText(){
alert('test');
var doc = new DOMParser().parseFromString(returnText, 'text/html');
// Create an hidden input
var hiddenInput = document.createElement("input");
// passed text into the input
hiddenInput.setAttribute("value", doc.body.textContent);
// Append the hiddenInput input to the body
document.body.appendChild(hiddenInput);
// select the content
hiddenInput.select();
// Execute the copy command
document.execCommand("copy");
// Remove the input from the body after copy text
document.body.removeChild(hiddenInput);
// store target button label value
var orignalLabel = event.getSource().get("v.label");
// change button icon after copy text
event.getSource().set("v.iconName" , 'utility:check');
// change button label with 'copied' after copy text
event.getSource().set("v.label" , 'Copied');
}