Advertisement
728x90
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
1document.querySelector("#copy-button").onclick = function () {
2 // Select the content
3 document.querySelector("#copy-input").select();
4 // Copy to the clipboard
5 document.execCommand("copy");
6 };Advertisement
Responsive Ad
🎯 Practice NowRelated Challenge
JavaScript Coding Exercise 35
Test your knowledge with this interactive coding challenge.
Start CodingAdvertisement
728x90
377of476