Hi Developers,
In this example on clicking the button the function gets triggered and then the query selector gets executed using the tag name. Using the query selector the tag gets selected and then the document.execCommand('copy'); gets executed to copy the contents in the textarea field.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Create a Copy to Clipboard Using JQuery</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>Create a Copy to Clipboard Using JQuery</h3>
<textarea id="comment" rows="10"></textarea>
<p><button type="button">Copy To Clipboard</button></p>
</body>
</html>
We hope it helps everyone. Thanks for supporting ITSolutionsGuides and keep supporting us also follow us in social media platforms.
Be the first to know about releases and tutorial news and solutions.
We care about your data in our privacy policy.
ITSolutionsGuides was started mainly to provide good and quality web solutions for all the developers. We provide tutorials to support all the developers and also we try to provide solutions to the errors we face while coding.
Copyright © 2023 - 2024 All rights reserved | ITSolutionsGuides