JavaScriptNo Comments

default thumbnail

In this article, we will tell you how to copy text to the clipboard with javascript. Click on the button to copy the text from the text field and paste it where you want.

HTML

<input type="text" value="This is dummy text" id="textbox">
<button onclick="copytextfn()">Copy text</button>

Javascript

function copytextfn() {
  var copyText = document.getElementById("textbox");
  copyText.select();
  document.execCommand("copy");
  alert("Result is: " + copyText.value);
}

This function is mostly used in web tools which are used to convert the text and copy it

Be the first to post a comment.

Add a comment