How we can use Copy to Clipboard using JQuery?

Most the browsers have the ability to programmatically copy a selection of text to the clipboard using document.execCommand("copy").
Here’s a code example:

$(document).on('click','.copybtn', function(){
    $(this).parents('.content').find('.copyText').select();
    document.execCommand("copy");
    console.log('text copied!');
});

HTML:

<div class="content">
    <input class="copyText" value="Contents to copied"/>
    <button type="button" class="copybtn">click here to copy</button>
</div>

I got some help from this article but not working for me so I have modified it as per my requirements.
To get more knowledge about the JQuery topics, you can check these articles too.

Please follow and like us:

Related Posts

Leave a Reply

Share