I made a copy and paste functionality and here it is
<script type="text/javascript">
function CopyToClipboard(containerid) {
if (document.selection) {
var range = document.body.createTextRange();
range.moveToElementText(document.getElementById(containerid));
range.select().createTextRange();
document.execCommand("copy");
} else if (window.getSelection) {
var range = document.createRange();
range.selectNode(document.getElementById(containerid));
window.getSelection().addRange(range);
document.execCommand("copy");
alert("text copied, copy in the text-area")
}
}
</script>
and on my html
<strong>Referral Link: </strong>
<div id="div1"><?php echo $investors[0]['referal_code'];?></div>
<button class="btn" id="copy" onclick="CopyToClipboard('div1')"><i class="la la-copy"></i></button>
The problem is that I cant copy the value of the echo
but when I tried to change what inside of my div like asdasd
it copies successfully
why is that?