function copyToClipboard(id, isHTML = true) { /* copy text to clipboard by element id set isHTML to false to copy plain text to the clipboard the default copy to the clipboard is HTML format */ function handler (event){ if(isHTML){ event.clipboardData.setData('text/html', $("#" + id).html()); } else{ event.clipboardData.setData('text/plain', $("#" + id).text()); } event.preventDefault(); document.removeEventListener('copy', handler, true); } document.addEventListener('copy', handler, true); document.execCommand('copy'); }