function copyToClipboard(container) { const el = document.createElement('textarea'); el.value = container.textContent.replace(/\n$/, ''); document.body.appendChild(el); el.select(); document.execCommand('copy'); document.body.removeChild(el); } function setupCodeCopy() { $('pre.highlight').prepend('
'); $('.copy-clipboard').on('click', function() { copyToClipboard(this.parentNode.children[1]); }); }