export const copyToClipboard = function (text, onComplete) {
if (navigator.clipboard) {
navigator.clipboard.writeText(text)
.then(() => {
if (typeof onComplete === 'function') onComplete();
})
.catch(err => {
console.warn('Copy fail', err);
});
} else {
let area = document.createElement('textarea');
document.body.appendChild(area);
area.value = text;
area.select();
document.execCommand('copy');
document.body.removeChild(area);
if (typeof onComplete === 'function') onComplete();
}
};
const element = document.querySelector('...');
copyToClipboard(element.innerText, () => {
alert('Copied to clipboard!' + '\n' + element.innerText);
});