copy text to clipboard from Dom Element
<div id="some-id">Text to copy</div>
copyToClipboard('some-id');
function copyToClipboard(containerid) {
  if (document.selection) {
    let range = document.body.createTextRange();
    range.moveToElementText(document.getElementById(containerid));
    range.select().createTextRange();
    document.execCommand("copy");
  } else if (window.getSelection) {
    let range = document.createRange();
    range.selectNode(document.getElementById(containerid));
    window.getSelection().removeAllRanges();
    window.getSelection().addRange(range);
    document.execCommand("copy");
    window.getSelection().removeAllRanges();
  }
}
by გიორგი უზნაძე
4 years ago
JavaScript
DOM
3
Pro tip: use ```triple backticks around text``` to write in code fences