Ask coding questions

← Back to all posts
Copy to clipboard
cannonthepom123

How do I make a 'copy to cliboard' button?
All the online tutorials on how to do it aren't working.

Answered by InvisibleOne [earned 5 cycles]
View Answer
Voters
cannonthepom123
Comments
hotnewtop
InvisibleOne

Here's the code I used:

HTML

in the JS

Let me know if that works for you

cannonthepom123

@InvisibleOne
IT WORKS!!!!! I guess it needed to be a text area.

InvisibleOne

Yes, it needs to be a textarea or input with a type of text.
I hacky way to display it differently is to have two sets of text. One that the user sees and the second that is invisible and is the one that is copied and pasted.
@cannonthepom123