I need JQuery or javascript to copy 1 column to the clipboard

I want to write some JQuery or javascript that will make clickable the first column (currency) in this table and copy the text from column two (Wallet) to the clipboard.  I need it to work for most browsers and IOS / Android.

This is a JQuery datatable in an ASP.Net / Razor environment.

<table id="dt_LiveCoinWallets" class="table table-striped table-bordered table-hover table-condensed">
                            <thead>
                                <tr>
                                    <th title="Click to select column">
                                        <h3>Copy</h3>
                                    </th>
                                    <th>
                                        <h3>Your Wallet Address</h3>
                                    </th>
                                </tr>
                            </thead>
                            @foreach (var item in Model)
                            {
                                <tr>
                                    <td>
                                        @Html.DisplayFor(modelItem => item.Currency)
                                    </td>
                                    <td>
                                        @Html.DisplayFor(modelItem => item.Wallet)
                                    </td>
                                </tr>
                            }
                        </table>

Open in new window

CAMPzxzxDeathzxzxAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Julian HansenCommented:
To do this you need to put your target data in an input or textarea. You can then use the HTMLInputElement.select() function.

Here is some sample code
HTML
<table id="dt_LiveCoinWallets" class="table table-striped table-bordered table-hover table-condensed">
<thead>
  <tr>
	<th title="Click to select column">
	  <h3>Copy</h3>
	</th>
	<th>
	  <h3>Your Wallet Address</h3>
	</th>
  </tr>
</thead>
<tbody>
  <tr>
	<td>USD</td>
	<td><input type="text" readonly value="1234567890"/></td>
  </tr>
  <tr>
	<td>GBP</td>
	<td><input type="text" readonly value="2468101214"/></td>
  </tr>
  <tr>
	<td>EUR</td>
	<td><input type="text" readonly value="135791113"/></td>
  </tr>
  <tr>
	<td>ZAR</td>
	<td><input type="text" readonly value="1123581321"/></td>
  </tr>
  <tr>
	<td>XBT</td>
	<td><input type="text" readonly value="3141592659"/></td>
  </tr>
</tbody>
</table>

Open in new window

jQuery
<script>
$(function() {
  $('#dt_LiveCoinWallets tbody tr td:first-child').click(function(e) {
    var el = $(this).next().find('input')[0];
    el.select();
    document.execCommand("Copy");
    alert("Copied " + el.value);
  });
});
</script>

Open in new window


Working sample here
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
CAMPzxzxDeathzxzxAuthor Commented:
Works like a champ.  Thank you!
0
Julian HansenCommented:
You are welcome.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
iOS

From novice to tech pro — start learning today.