Horje
copy clipboard with span Code Example
[Solved] - copy clipboard with span Code Example
Try following codes
js copy span text to clipboard
document.getElementById("cp_btn").addEventListener("click", copy_password);

function copy_password() {
    var copyText = document.getElementById("pwd_spn");
    var textArea = document.createElement("textarea");
    textArea.value = copyText.textContent;
    document.body.appendChild(textArea);
    textArea.select();
    document.execCommand("Copy");
    textArea.remove();
}
copy clipboard with span
<span id="to-select-text">1111 - 2222 - 3333 - 4444</span>
<button id="copy-button">Copy</button>
Date: 2022-05-21 05:02:10
Category: whatever
More for You