DEV Community

loading...

Copy To Clipboard JQuery

websolutionstuff profile image Websolutionstuff Originally published at websolutionstuff.com ・1 min read

In this small tutorial I will explain you how to copy text from one field to another field using java script, many time we have requirement to copy text value one field to another field, like current address and permanent address are same in this criteria copy to clipboard is useful to save our time.

So here I will give you some piece of code how to copy to clipboard using JQuery.

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Copy To Clipboard Using JQuery-websolutionstuff.cpm</title>
<script src="https://code.jquery.com/jquery-3.5.1.js"></script>
<script>
    $(document).ready(function(){
        $("button").click(function(){
            alert("Success");
            $("textarea").select();
            document.execCommand('copy');
        });

    });
</script>
</head>
<body>
    <textarea id="comment" rows="5" cols="50"></textarea>
    <p><button type="button">Get Value</button></p>
    <p><strong>Note:</strong> Type something in the textarea and click the button to see the output.</p>
</body>
</html>
Enter fullscreen mode Exit fullscreen mode

And Don't Forgot to Like, Share and Comment.

Read Also : How To Generate QRCode In Laravel

Discussion (1)

pic
Editor guide

Some comments have been hidden by the post's author - find out more