SoFunction
Updated on 2025-04-10

jquery copy to clipboard with one click

Today, I have a function to copy a piece of text to the clipboard by clicking on the event. I found some online and sorted it out for friends who need it.

<a  data-text="123456">Copy text</a>
$(function(){
    var clipboard = new Clipboard('#copy',{ 

       text: function(trigger) { 

          alert("Copy successfully!");

          return ('data-text'); 

       }

    });
});

The above example of jquery copying to the clipboard with one click is all the content I share with you. I hope you can give you a reference and I hope you can support me more.