I am trying to copy a div to the clipboard. The div has a few styles, including a background. I have made a script to copy the div to the clipboard, but I can't figure out how to do the background.
I have seen this done, but I can't remember how.
Any help would be appreciated.
This is as far as I got:
function executeCopy(text) {
var copyDiv = document.createElement('div');
copyDiv.contentEditable = true;
document.body.appendChild(copyDiv);
copyDiv.innerHTML = text;
copyDiv.unselectable = "off";
copyDiv.focus();
document.execCommand('SelectAll');
document.execCommand("Copy", false, null);
document.body.removeChild(copyDiv);
}
#foo {
background-color: red;
font-family: cursive;
}
<div id="foo">Test</div>
<button onclick="executeCopy(document.getElementById('foo').innerHTML);">Copy</button>