---
title: "Discussion on \"💡 Easy Copy to Clipboard Button in Vanilla JavaScript\" | Hashnode"
description: "Discussion on \"💡 Easy Copy to Clipboard Button in Vanilla JavaScript\". 👋 Welcome back developers.\nSo, in this article we will see how we can create a simple Copy to Clipboard functionality in JavaScript.\n\nNote: This will only work if you want to copy text inside of an input or textarea. It can't be done with any other ..."
url: "https://hashnode.com/posts/easy-copy-to-clipboard-button-in-vanilla-javascript/5fadfe62fa438d6532c7eb54"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [💡 Easy Copy to Clipboard Button in Vanilla JavaScript](https://blog.usmans.me/easy-copy-to-clipboard-button-in-vanilla-javascript?utm_source=hashnode&utm_medium=feed)

👋 Welcome back developers. So, in this article we will see how we can create a simple Copy to Clipboard functionality in JavaScript. Note: This will only work if you want to copy text inside of an input or textarea. It can't be done with any other ...

Nov 13, 2020 · 4 min read · blog.usmans.me  
Updated Nov 14, 2020  
Read the article

-   [#2articles1week-1](https://hashnode.com/tag/2articles1week-1)
-   [#javascript](https://hashnode.com/tag/javascript)
-   [#web-development](https://hashnode.com/tag/web-development)
-   [#js](https://hashnode.com/tag/js)
-   [#2articles1week](https://hashnode.com/tag/2articles1week)

## Written by

[Usman Sabuwala](https://hashnode.com/@usmanwrites)

@usmanwrites · India

  
[View profile](https://hashnode.com/@usmanwrites)

Learning web development, running a YouTube channel

I am a full stack developer, YouTuber and blogger!

## Responses 2

Markdown supported · ⌘↵ to post

[jad inerky](https://hashnode.com/@jadinerky)

[Nov 13, 2020](https://hashnode.com/posts/easy-copy-to-clipboard-button-in-vanilla-javascript/5fadfe62fa438d6532c7eb54/comment/5faed4d67fcc8d387fc0d33e)

good post but I must suggest you mention that the

```
document.execCommand('copy');
```

is not a good solution, knowing that it might be removed at any time from any browser, [See Docs](https://developer.mozilla.org/en-US/docs/Web/API/Document/execCommand) and you can advise people to use a more stable and safe method as the [Clipboard API](https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/Interact_with_the_clipboard) still the best solution for me is to use them both, I can use the Clipboard API and the .execCommand() as a fallback

[Usman Sabuwala](https://hashnode.com/@usmanwrites)

[Nov 14, 2020](https://hashnode.com/posts/easy-copy-to-clipboard-button-in-vanilla-javascript/5fadfe62fa438d6532c7eb54/comment/5faed4d67fcc8d387fc0d33e#reply-5faf581e7fcc8d387fc0d778)

Thanks for the suggestion. I haven't used the Clipboard API yet but I am looking into it and I will write an updated version of this blog post using the Clipboard API. I chose `execCommand` as I think this is the easiest way possible to achieve the goal

[jad inerky](https://hashnode.com/@jadinerky)

[Nov 14, 2020](https://hashnode.com/posts/easy-copy-to-clipboard-button-in-vanilla-javascript/5fadfe62fa438d6532c7eb54/comment/5faed4d67fcc8d387fc0d33e#reply-5fafd49bab2abe435ce68e99)

[Usman Sabuwala](https://hashnode.com/@usman2102) you are right, it's the easiest way to do it.

[Varun Sridharan](https://hashnode.com/@varunsridharan)

[Nov 13, 2020](https://hashnode.com/posts/easy-copy-to-clipboard-button-in-vanilla-javascript/5fadfe62fa438d6532c7eb54/comment/5fae12f68f0a02655347962b)

Great Post. I was looking for it. :-)

[Usman Sabuwala](https://hashnode.com/@usmanwrites)

[Nov 13, 2020](https://hashnode.com/posts/easy-copy-to-clipboard-button-in-vanilla-javascript/5fadfe62fa438d6532c7eb54/comment/5fae12f68f0a02655347962b#reply-5fae5f1cfa438d6532c7ef72)

Thank you so much! I am glad it helped.
