Copy text without typing or buttons
P粉785522400
P粉785522400 2023-08-30 09:21:39
0
1
470
<p>How do I create a function that copies text to the clipboard? I found on w3schools how to do it using an input box, but I don't know how to do it using just text (like Hypixel for example)</p>
P粉785522400
P粉785522400

reply all(1)
P粉978742405

You don't need to use a library to accomplish 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">复制这段文字</div>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!