CoPY to CLIPBOARD in JavaScript !

neeswebservices

Nischal Dahal

Posted on May 27, 2022

CoPY to CLIPBOARD in JavaScript !

Copy using javascript in proper way !

function copyme(e) {
    e = e || window.event;
    let target = e.target || e.srcElement;
 // const text = target.previousElementSibling.innerHTML;
        let text = e.target.value; // getting directly from input element 
    const el = 
 document.createElement('textarea');
    el.value = text;
    document.body.appendChild(el);
    el.select();
    document.execCommand('copy');
    document.body.removeChild(el);
}

Enter fullscreen mode Exit fullscreen mode
💖 💪 🙅 🚩
neeswebservices
Nischal Dahal

Posted on May 27, 2022

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related