Copy to clipboard when clicking text, using clipboardjs


I want some text to be automatically copied to the clipboard when clicking on it. I followed what clipboardjs says on their website but I can’t recreate the behavior. My theme, CodeIT, uses clipboardjs.

This is how it’s supposed to work, according to clipboardjs.

A pretty common use case is to copy content from another element. You can do that by adding a data-clipboard-target attribute in your trigger element.
The value you include on this attribute needs to match another’s element selector.

<!-- Target -->
<input id="foo" value="">
<!-- Trigger -->
<button class="btn" data-clipboard-target="#foo">
    <img src="assets/clippy.svg" alt="Copy to clipboard">

None of this works.

Would appreciate some help. :slight_smile:

This is not related to Hugo. Please take your question to Stack Exchange or similar. Thanks.