Copy To Clipboard JQuery Example

In this tutorial I will explain you how to copy to clipboard jquery example, many time we have requirement to copy text value one field to another field, like current address and perminant address etc. If you are working with inputs or textarea or div, you might need to create a button like "Copy to Clipboard" to copy all contents of input or div to user's clipboard using jquery or javascript.

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 example - techsolutionstuff.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>
  <h3>Copy To Clipboard JQuery Example - techsolutionstuff.com</h3>
    <textarea id="comment" rows="5" cols="62"></textarea>
    <p><button type="button">Copy To Clipboard</button></p>
    <p><strong>Note:</strong> Type something in the textarea and click the button to see the output.</p>
</body>
</html> 

 

 

You will get output like this :

Copy To Clipboard JQuery Example

 


You might also like :

FEATURE POSTS