Copy Text to Clipboard
function copyToClipboard() { const copyText = document.getElementById("myInput"); copyText.select(); document.execCommand("copy"); } //new API function copyToClipboard(){ navigator.clipboard.writeText(document.querySelector('#myInput').value).then(function() { /* clipboard successfully set */ }, function() { /* clipboard write failed */ });
}
In the meantime, if you have any JavaScript questions, feel free to contact me. I'll do by best to create free articles to answer your questions.
Please follow me on LinkedIn / Twitter / Facebook / Codesandbox / Codepen.