Answers for "click text to copy javascript"

3

copy text to clipboard javascript

//As simple as this
navigator.clipboard.writeText("Hello World");
Posted by: Guest on February-23-2021
11

js copy text to clipboard

function copy() {
  var copyText = document.querySelector("#input");
  copyText.select();
  document.execCommand("copy");
}

document.querySelector("#copy").addEventListener("click", copy);
Posted by: Guest on September-17-2019
0

Javascript copy text onclick

const span = document.querySelector("span");

span.onclick = function() {
  document.execCommand("copy");
}

span.addEventListener("copy", function(event) {
  event.preventDefault();
  if (event.clipboardData) {
    event.clipboardData.setData("text/plain", span.textContent);
    console.log(event.clipboardData.getData("text"))
  }
});
Posted by: Guest on June-28-2021

Code answers related to "click text to copy javascript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language