How to copy text to a clipboard
In this tutorial, we will read How to copy text to a clipboard. clipboard copy text from one field to another field using javascript. you can copy the clipboard using javascript commands like document.execCommand(“copy”). many times we have requirements to copy text values from one field to another field, like current address, permanent address, etc. are the same in this criteria copy to the clipboard is useful to save time.
Example
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>How to copy text to clipboard using jquery - devnote.in </title>
<script src="https://code.jquery.com/jquery-3.5.1.js"></script>
<script>
$(document).ready(function(){
$(".clipboard").click(function(){
console.log("Successfully copy!");
$("textarea").select();
document.execCommand('copy');
});
});
</script>
</head>
<body style="text-align: center">
<h1>How to copy text to clipboard using jquery</h1>
<textarea id="comment" rows="6" cols="60"></textarea>
<p><button type="button" class="clipboard">Copy value</button></p>
</body>
</html>