0

so i have a situation here.the cards are being generated dynamically. the discount coupon is shown only after the user loginIn. once the discount coupon is shown,

<div class='col-md-2' style='position: relative;height: 200px;' 
id='showcode'>
<div class="geodir-category-options fl-wrap"style='position: 
absolute;bottom: 0;' >
<div class="listing-rating card-popup-rainingvis">
<a class="trs-btn1 pointer" onmouseover='mover(this.id)' 
onclick="checkSignIn("+i+");" id="+"btn".concat(i.toString()) 
style="margin-top: 0px" >Show discount code</a>

</div>
</div>
</div> 

onclick on the discount code it should copy text to clipboard.

1 Answers1

0

You can use the select() method and execCommand() in order to copy text inside an element.

var txt = document.querySelector("ELEMENT_T0_BE_COPIED");
//selecting the text inside the element.
txt.select();
//copying content in to the clipboard
document.execCommand("copy");

//store the clipboard value in a variable.
var clipVal = txt.value;

You can learn more here

Seniru Pasan
  • 753
  • 1
  • 7
  • 13