Create Dream Website

How to create a “Copy Link” button (Elementor Tutorial)

Copy link Button , copy link button in wordpress website

Add id "copyButton" to button

JavaScript
<script>
  document.addEventListener("DOMContentLoaded", function() {
    const textToCopy = "This is the text to copy."; // Replace with your desired text
    const copyButton = document.getElementById("copyButton");

    copyButton.addEventListener("click", function() {
        // Create a temporary input element
        const tempInput = document.createElement("input");
        tempInput.value = textToCopy;

        // Append the input element to the document
        document.body.appendChild(tempInput);

        // Select the text in the input element
        tempInput.select();

        // Copy the selected text to the clipboard
        document.execCommand("copy");

        // Remove the temporary input element
        document.body.removeChild(tempInput);

        // Show an alert message
        alert("Text copied to clipboard successfully!");
    });
});


</script>

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top