Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to copy href atrribute by clipboard.js

after click a button .btn, I would like to copy a href atrribute on a clipboard.

here is the html source(clipboard.js recognize any type as button)

<a class="btn" href="#oops"><h1>Button</h1></a>

and below is the script:

<script type="text/javascript">
        new Clipboard(".btn", {
          text: function(trigger) {
            return $(trigger).getAttribute("href");
          }
        });
</script>   

But I cannot make it work successfully. If someone would help me a second i would be very grateful.

like image 481
Minseok Jeon Avatar asked Dec 16 '25 12:12

Minseok Jeon


1 Answers

It works for me

new Clipboard('.btn', {
    text: function (trigger) {
        return trigger.getAttribute('href');
    }
});
<script src="//cdnjs.cloudflare.com/ajax/libs/clipboard.js/1.4.0/clipboard.min.js"></script>
<a class="btn" href="#oops"><h1>Button</h1></a>
like image 118
Mostafa Sabeghi Avatar answered Dec 19 '25 06:12

Mostafa Sabeghi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!