JS: 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);
βˆ‘ JS in Depth
XAH Β BUY NOW

JS in Depth

JS Obj Reference

DOM


DOM

Overview

Basic Examples

HTML Input

Web Scripting Examples

Web Scripting Misc

jQuery

node.js