<body> <div id="a">test - a</div> <div id="b">test - b</div> <script> function test(text) { navigator.clipboard.writeText(text); } var div = document.querySelector('div#a'); div.onclick = function () { test(div.innerHTML); } </script>
<body> <div id="a">test - a</div> <div id="b">test - b</div> <script> function test(text) { navigator.clipboard.writeText(text); } var div = document.querySelector('div#a'); div.onclick = function () { test(div.innerHTML); } </script>