JavaScript Internals (521 Qs)•Part 6: Async Internals, Memory, Microtasks & Web APIs (329 - 403)
How do you create copy to clipboard button
You need to select the content(using .select() method) of the input element and execute the copy command with execCommand (i.e, execCommand('copy')). You can also execute other system commands like cut and paste.
javascript
document.querySelector("#copy-button").onclick = function () {
// Select the content
document.querySelector("#copy-input").select();
// Copy to the clipboard
document.execCommand("copy");
};