Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Get the text you want to copy
- var textToCopy = "Hello, World!";
- // Create a textarea element dynamically
- var textarea = document.createElement('textarea');
- // Set the value of the textarea to the text you want to copy
- <textarea.value = textToCopy;
- // Append the textarea to the document
- document.body.appendChild(textarea);
- // Select the text inside the textarea
- <textarea.select();
- // Copy the selected text to the clipboard
- document.execCommand('copy');
- // Remove the textarea from the document
- document.body.removeChild(textarea);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement