-1

How can I create an text to clipboard function? I found on w3schools how to do it with an input but I don't know how to do it with just text (for example like Hypixel

1 Answers1

0

You don't need an library to do this.
Just use document.execCommand("copy")

$("#txt").on("click", function (event) {
    var $temp = $("<input>");
    $("body").append($temp);
    $temp.val($("#txt").html()).select();
    document.execCommand("copy");
    $temp.remove();
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<div id="txt">Copy this text</div>
Webdeveloper_Jelle
  • 2,868
  • 4
  • 29
  • 55