Skip to content

Instantly share code, notes, and snippets.

@nocodesupplyco
Last active April 5, 2024 01:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nocodesupplyco/a5a83ad77815280560125a5685db7430 to your computer and use it in GitHub Desktop.
Save nocodesupplyco/a5a83ad77815280560125a5685db7430 to your computer and use it in GitHub Desktop.
Click to Copy to Clipboard
<!-- Example HTML with the "data-clipboard-text" attribute which holds the content to be copied -->
<div class="copy-btn" data-clipboard-text="28A745">Copy the attribute</div>
<!-- Place this before the end of the </body> -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/clipboard.js/1.7.1/clipboard.min.js"></script>
<script>
var clipboard = new Clipboard('[data-clipboard-text]');
clipboard.on('success', function(e) {
console.log(e);
$('.copy-btn').click();
});
clipboard.on('error', function(e) {
console.log(e);
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment