JSFiddle - React, Tailwind, and code Playground
HTML
<div>
<span id='test'>This is a test</span>
</div>
<button onclick='copyDivToClipboard("test")'>Copy to clipboard</button>
JavaScript
function copyDivToClipboard(elem) {
var range = document.createRange();
range.selectNode(document.getElementById(elem));
window.getSelection().removeAllRanges();
window.getSelection().addRange(range);
document.execCommand("copy");
window.getSelection().removeAllRanges();
}