1var copy = document.querySelectorAll(".copy");
2
3for (const copied of copy) {
4 copied.onclick = function() {
5 document.execCommand("copy");
6 };
7 copied.addEventListener("copy", function(event) {
8 event.preventDefault();
9 if (event.clipboardData) {
10 event.clipboardData.setData("text/plain", copied.textContent);
11 console.log(event.clipboardData.getData("text"))
12 };
13 });
14};
1const span = document.querySelector("span");
2
3span.onclick = function() {
4 document.execCommand("copy");
5}
6
7span.addEventListener("copy", function(event) {
8 event.preventDefault();
9 if (event.clipboardData) {
10 event.clipboardData.setData("text/plain", span.textContent);
11 console.log(event.clipboardData.getData("text"))
12 }
13});