JSFiddle - React, Tailwind, and code Playground

by timothyarmstrong

HTML

<input type="text" id="text" />
<button id="button">Copy Text</button>

<textarea id="copy-workaround"></textarea>

JavaScript

function to_clipboard(text) {
    var textarea = document.getElementById("copy-workaround");
    textarea.value = text;
    textarea.select();
    document.execCommand("copy", false, null);
}

var text = document.getElementById('text');
var button = document.getElementById('button');

button.addEventListener('click', function() {
    to_clipboard(text.value);
}, false);