Javascript Function copyToClipboard(elem) Copy Text to Clipboard
Javascript Function Code to Copy Elements InnerHTML/Text to Clipboard. Function Can Easily be Modified to Suite your Needs
Home
Short:
/*-------------------------------------------------- copy innerHTML of [elem] to clipboard you can pass elem via document.querySelector or document.querySelectorAll ------------------------------------------------ */ function copyToClipboard(elem) { navigator.clipboard.writeText(elem.innerHTML).then(() => { console.log('Content copied to clipboard'); },() => { console.error('Failed to copy'); }); }
source code home