JSFiddle - React, Tailwind, and code Playground
by philll_t
HTML
<textarea id="code" readonly>
<html>
Hello
</html>
</textarea>
<div id="success" style="display: none;">
success
</div>
<script>
const textArea = document.getElementById("code");
textArea.addEventListener("click", function () {
textArea.select();
try {
var successful = document.execCommand('copy');
var msg = successful ? 'successful' : 'unsuccessful';
console.log('Fallback: Copying text command was ' + msg);
alert("copy success!");
const successMsg = document.getElementById("success");
successMsg.style.display = 'block';
} catch (err) {
console.error('Fallback: Oops, unable to copy', err);
}
})
</script>