0

I'm trying to get a copy-to-clipboard function to work for below HTML-code using the Clipboard.js library:

<table id="test">
<tr><td class="c2c"><a id="1" class="btn fa fa-clipboard fa-2x" data-clipboard-action="copy" data-clipboard-target="1" data-value="http://some/link/1"></a></td></tr>  
<tr><td class="c2c"><a id="2" class="btn fa fa-clipboard fa-2x" data-clipboard-action="copy" data-clipboard-target="2" data-value="http://some/link/2"></a></td></tr>  
<tr><td class="c2c"><a id="3" class="btn fa fa-clipboard fa-2x" data-clipboard-action="copy" data-clipboard-target="3" data-value="http://some/link/3"></a></td></tr>  
</table>

As you can see the value/ID changes for each td or a-element.

Instead of ID can I also use a class element to work with clipboard.js?

With this code I get the correct values but I cannot get it to work with clipboard.js:

    $("#test").on('click', '.btn', function (e) {
        e.preventDefault();
        var id = $(this).data('value');
        console.log(id)
    });

How can I get the value of the data-value attribute for each td and have it copied with clipboard.js?

Thank you.

ratanmalko
  • 449
  • 4
  • 20

0 Answers0