Copy Text Using Javascript Function

How to Copy Text Using Javascript Function


Here is The Video Documentation :- 

Here is The JavaScript Code To Copy ...


<script>
    function myFunction() {
      var copyText = document.getElementById("myInput");
      copyText.select();
      document.execCommand("copy");
      alert("Copied the text: " + copyText.value);
    }
</script>


This Code Will Copy The Whole Content Inside the Tag Where id is myInput  .


Click on the button to copy the text from the text field. Try to paste the text (e.g. ctrl+v) afterwards in a different window, to see the effect.

  Try The Coding Here :- https://www.w3schools.com/howto/tryit.asp?filename=tryhow_js_copy_clipboard


Here is How the Full Code Will Look Like :- 

<!DOCTYPE html>
<html>
<body>

<p>Click on the button to copy the text from the text field. Try to paste the text (e.g. ctrl+v) afterwards in a different window, to see the effect.</p>

<input type="text" value="Hello World" id="myInput">
<button onclick="myFunction()">Copy text</button>

<script>
function myFunction() {
  var copyText = document.getElementById("myInput");
  copyText.select();
  document.execCommand("copy");
  alert("Copied the text: " + copyText.value);
}
</script>

</body>
</html>