JavaScript: Copy Text

By Xah Lee. Date: .

Here is how to copy text using JavaScript.

test text

<p id="text39237">test text</p>

<button id="button23256" type="button">Copy</button>
const text39237 = document.getElementById("text39237");
const button23256 = document.getElementById("button23256");

const f_CopyText = (() => {
  navigator.clipboard.writeText(text39237.textContent);
});

button23256.addEventListener("click", f_CopyText, false);
BUY Ξ£JS JavaScript in Depth