1function copyToClipboard(element) {
2 var $temp = $("<input>");
3 $("body").append($temp);
4 $temp.val($(element).text()).select();
5 document.execCommand("copy");
6 $temp.remove();
7}
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});