Это вывод вашего текущего кода:
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.2.1/jquery.js">
</script>
<script>
function CopyCode(){
var text = document.getElementById("input-text");
text.select();
document.execCommand("copy");
}
var text = document.getElementById("element-id");
text.select();
document.execCommand("copy");
</script>
<input type="text" placeholder="CODE" value="CODE" style="text-align:center;" id="input-text"/>
<script type="text/javascript">
$('input').keypress(function(e) {
e.preventDefault();
});
</script>
<button onclick="CopyCode()">COPY</button> <br/> <br/>
<!--- SECOND --->
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.2.1/jquery.js">
</script>
<script>
function CopyCode(){
var text = document.getElementById("coupon2-text");
text.select();
document.execCommand("copy");
}
var text = document.getElementById("element-id");
text.select();
document.execCommand("copy");
</script>
<input type="text" placeholder="CODE" value="CODE" style="text-align:center;" id="coupon2-text"/>
<script type="text/javascript">
$('input').keypress(function(e) {
e.preventDefault();
});
</script>
<button onclick="CopyCode()">COPY</button> <br/> <br/>
Вот вывод обновленного кода:
function CopyCode(){
var text = document.getElementById("coupon2-text");
text.select();
document.execCommand("copy");
}
$("button").click(function() {
var textId = $(this).attr("class");
var text = document.getElementById(textId);
text.select();
document.execCommand("copy");
});
$('input').keypress(function(e) {
e.preventDefault();
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="text" placeholder="CODE" value="CODE 1" style="text-align:center;" id="coupon2-text"/>
<button class="coupon2-text">COPY</button> <br/> <br/>
<input type="text" placeholder="CODE" value="CODE 2" style="text-align:center;" id="input-text"/>
<button class="input-text">COPY</button> <br/> <br/>