Instead of Copy text using the shortcut (ctrl+c), JavaScript is the simplest way. We can use the copy command document.execCommand()
to copy text content to the clipboard using JavaScript.
Below is the sample code which will show how to copy text to the clipboard using JavaScript.
<input type="text" value="Love to Code" id="textInput"> <button onclick="copyText()">Copy</button>
<script> function copyText(){ var text = document.getElementById("textInput"); text.select(); document.execCommand("copy"); alert("Copied text: " + text.value); } </script>