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 }
1function copyToClipboard(text) {
2 const elem = document.createElement('textarea');
3 elem.value = text;
4 document.body.appendChild(elem);
5 elem.select();
6 document.execCommand('copy');
7 document.body.removeChild(elem);
8}
1function copy() {
2 var copyText = document.querySelector("#input");
3 copyText.select();
4 document.execCommand("copy");
5}
6
7document.querySelector("#copy").addEventListener("click", copy);
1// Since Async Clipboard API is not supported for all browser!
2function copyTextToClipboard(text) {
3 var textArea = document.createElement("textarea");
4 textArea.value = text
5 document.body.appendChild(textArea);
6 textArea.focus();
7 textArea.select();
8
9 try {
10 var successful = document.execCommand('copy');
11 var msg = successful ? 'successful' : 'unsuccessful';
12 console.log('Copying text command was ' + msg);
13 } catch (err) {
14 console.log('Oops, unable to copy');
15 }
16
17 document.body.removeChild(textArea);
18}
1$('.copyable').click(function (event) {
2 const targetInput = document.getElementById('copyable');
3 targetInput.select();
4 document.execCommand('copy');
5 //navigator.clipboard.writeText(targetInput.getAttribute('data-url'));
6 alert("Link Copied");
7});