Skip to main content
InterviewHubPRO
Section Overview
Q381

Question 381 of 536

Part 6: Async Internals, Memory, Microtasks & Web APIs (329 - 403)

71%
JavaScript & V8 Internals (536 Qs)•Part 6: Async Internals, Memory, Microtasks & Web APIs (329 - 403)

How do you create copy to clipboard button

senior LevelCode ExampleCLIAsync & PromisesEvent Loop

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");
  };