Code

Click to Copy to Clipboard

Add a click to copy to clipboard to your Webflow site using a Javascript snippet. This copy to clipboard functionality allows you to designate the class and text that you'll allow your users to copy.

Click to Copy to Clipboard preview

Add a click to copy to clipboard to your Webflow site using a Javascript snippet. This copy to clipboard functionality allows you to designate the class and text that you'll allow your users to copy.

How to add it

  1. Add the Javascript snippet code to the head section of your page custom code
  2. Add the Javascript script to your closing body custom code
  3. Add the HTML embed to your page
  4. Update the data-clipboard-text attribute with the text you want to copy

The code

Javascript
                      <!-- Add to header -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/clipboard.js/1.7.1/clipboard.min.js"></script>

<!-- Add to closing body -->
<script>
    var clipboard = new Clipboard('.copy-btn');
    clipboard.on('success', function(e) {
        console.log(e);
        $('.copy-btn').click();
    });
    clipboard.on('error', function(e) {
        console.log(e);
    });
</script>

                    
HTML
                      <div class="copy-btn" data-clipboard-text="28A745">Copy the attribute</div>

                    

Browse similar code snippets

Categories

Language

More from Corey Moen

Profile →

Related Webflow questions

All answers →

Similar code snippets

All code snippets →