I am trying to copy contents of a span element but I failed so far with no error in chrome:
const element = document.getElementById("element");
console.log(element.innerHTML); //consoles Data
//below doesn't copy contents of the element to clipboard
const node = document.createRange();
node.selectNode(element);
window.getSelection().removeAllRanges();
window.getSelection().addRange(node);
document.execCommand("copy");
<span id="element">Data</span>
Since I can see contents of the element via innerHTML, I am thinking the element is indeed accessible. Why cant I copy the text?