1//U need to have a button with the id the same as its name because it is going to be sent to the clipborad.
2/*Like this: */
3<button onClick="SelfCopy(this.id)" id="1">1</button>
4<button onClick="SelfCopy(this.id)" id="2">2</button>
5<button onClick="SelfCopy(this.id)" id="3">3</button>
6
7function SelfCopy(copyText)
8 {
9 navigator.clipboard.writeText(copyText);
10 alert("You just copied this: (" + copyText + ").");
11 }
1<head><script>
2function copyToCliBoard() {
3 var copyText = document.getElementById("myInput");
4 copyText.select();
5 copyText.setSelectionRange(0, 99999); /* For mobile devices */
6 document.execCommand("copy");
7 alert("Copied the text: " + copyText.value);
8}
9</script></head>
10
11<body>
12<input type="text" value="Hello World" id="myInput">
13<button onclick="copyToCliBoard()">Copy text</button>
14</body>
1$(document).ready(function(){
2 $("#ewefmwefmp").click(function(){
3 //alert()
4 var copyText = document.getElementById("myInput");
5 copyText.select();
6 copyText.setSelectionRange(0, 99999)
7 document.execCommand("copy");
8 alert("Copied the text: " + copyText.value);
9
10 });
11});