I want to copy the text from a button when I click on it. I reused code from w3 schools. The difference with the w3 schools code is that when you click on a button it copy the text from an input, I want to copy the text from the button I'm clicking on.
function copyClipboard() {
var copyText = document.getElementById("myButton").innerHTML;
document.execCommand("copy");
}
<button id="myButton" onclick="copyClipboard()">Text I want to copy</button>
When I console.log copyText it display the text from the button but my text is never copied.
Do you know why ?