I am trying to copy email text in html, that email text is in a href tag.
Means when any user click on icon near to email text then it should be copied only email value but it is not working.
Instead of only email my code is copying full js function text, below is full code and also output what is coming when we click on copy icon.
Below is full code.
<td class="col-md-3 contactTable">
<a href="mailto:@Model.UsersEmail[item.ID]" id="a1">@Model.UsersEmail[item.ID]</a>
<i class="fa fa-copy" onclick="copyToC('#a1')" style="font-size:17px;"></i>
</td>
<script type="text/javascript">
function copyToC(element) {
var $temp = $("<input>");
$("body").append($temp);
$temp.val($(element).text()).select();
document.execCommand("copy");
$temp.remove();
}
Below is copied text when we click on copy icon:
<script type="text/javascript"> function copyToC(element) { var $temp = $("<input>"); $("body").append($temp); $temp.val($(element).text()).select(); document.execCommand("copy"); $temp.remove(); }