Copying text to clipboard with JavaScript

In this article, I will be explaining in depth how the copyToClipboard snippet from 30 seconds of code works. You can find the source code for it and a ton of other useful methods in the project’s repository.

30 seconds of code: Javascript snippets that you can understand in 30 seconds or lessCore functionality

One thing that comes up quite often in website building is the ability to copy some text to clipboard, without the user selecting it or hitting the appropriate key combination on their keyboard. Javascript can easily do this in five short steps:
  1. Create a