How to copy text onclick event using jquery. Here simple example. You can use it anywhere.
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script>
function copytxt(which_id) {
var $temp = $("<input>");
$("body").append($temp);
$temp.val($(which_id).text()).select();
document.execCommand("copy");
$temp.remove();
}
</script>
</head>
<body>
<p id="mlink"> My Text </p>
<span class="btn btn-success" style="cursor: pointer" onclick="copytxt('#mlink')">
Click to copy Text
</span>
</body>
</html>
Get the latest news and updates by signing up to our daily newsletter.We won't sell your email or spam you !