JSFiddle - React, Tailwind, and code Playground
HTML
<div>
<p id="text">RANDOM TEXT</p>
<img id="image" width="100" src="http://icons.iconarchive.com/icons/paomedia/small-n-flat/1024/sign-check-icon.png">
<button onclick="copyElement('image');">Copy image</button>
<button onclick="copyElement('text');">Copy text</button>
</div>
JavaScript
function copyElement(id) {
var element = document.getElementById(id);
var range = document.createRange();
range.selectNode(element);
window.getSelection().removeAllRanges();
window.getSelection().addRange(range);
document.execCommand('Copy');
}