Copy Text to Clipboard with Line Breaks | thiscodeWorks

PHOTO EMBED

Sat Sep 11 2021 08:26:55 GMT+0000 (UTC)

Saved by @ajidstark #javascript

function copyToClipboard(){
 
    var codeToBeCopied = document.getElementById('code-snippet').innerText;
    var emptyArea = document.createElement('TEXTAREA');
    emptyArea.innerHTML = codeToBeCopied;
    const parentElement = document.getElementById('post-title');
    parentElement.appendChild(emptyArea);
 
    emptyArea.select();
    document.execCommand('copy');
 
    parentElement.removeChild(emptyArea);
    M.toast({html: 'Code copied to clipboard'})
 
    }
content_copyCOPY

https://www.thiscodeworks.com/copy-text-to-clipboard-with-line-breaks/5c2917f164936a00141e1c03