
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>