DEV Community

Discussion on: How to copy text to the clipboard with JavaScript (5 lines of code)?

Collapse
 
ibrahima92 profile image
Ibrahima Ndaw • Edited
1 const copyText = document.querySelector("#copyMe")
2 const copyMeOnClipboard = () => {
3 copyText.select()
4 copyText.setSelectionRange(0, 99999) // used for mobile phone
5 document.execCommand("copy") }

That's the code that does the copy.