We have seen many websites have the option to copy a block of text by clicking a button. Letβs learn how to build this using vanilla JavaScript.
Steps to copy text in javascript
1. Create a textarea element
2. Get the text from the div using div.innerText
3. Set the value of textarea with the text we retrived
4. Then select the text using select() method
5. Then use the method document.execCommand('copy') to copy text.
NOTES: Don't forgot to set text area width and height, and also DO NOT set "display : none" property to the textarea.
