Dear Mates, Please click the ads to support us.
Tutorial

Copy Text to Clipboard JQuery

Kailash Singh Oct 24, 2021 5231 Views
Kailash Singh

Copy Text to Clipboard JQuery Share

Published Oct 24, 2021 by Kailash Singh 0 Comments 5231 Views

In this tutorial, we are going to teach, how to create simple JQuery code to copy the text to the clipboard.

Here I make a simple button to copy the code.

 

Create text and Button

<h3 id="copy">I am copy this text</h3>
<button onclick="copyToClipboard('#copy')" class="btn btn-primary" title="Click to Copy">Copy</button>

In this button, we are creating a onclick function to copy the code.

 

JQuery code

You can create a function to copy the code.

<script type="text/javascript">
  function copyToClipboard(element) 
  {
    var $temp = $('<input>');
    $("body").append($temp);
    $temp.val($(element).text()).select();
    document.execCommand("copy");
    $temp.remove();
  }
</script>

 

Comments 0