DEV Community

Bret
Bret

Posted on

3

how do you onClick, COPY text? (im making a app)

how do you "copy" the text that's within a class or id?
I want to build a app, that I can add custom snippets to, that I can just click a button... to copy... the snippet to paste.

what would that look like?

Top comments (3)

Collapse
 
juneikerc profile image
Juneiker

there are different ways to do that, personally I use navitagor.clipboard but you can also use Document.execCommand.

developer.mozilla.org/en-US/docs/W...
30secondsofcode.org/blog/s/copy-te...

Collapse
 
rishitkhandelwal profile image
Rishit Khandelwal • Edited

Well, navigator.clipboard ig?

Some comments may only be visible to logged-in visitors. Sign in to view all comments.

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay