Answers for "how to copy text from input through button click js"

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
0

how to copy text from input through button click js

function copyToClipboard(element) {
  var $temp = $("<input>");
  $("body").append($temp);
  $temp.val($(element).text()).select();
  document.execCommand("copy");
  $temp.remove();
}
Posted by: Guest on February-21-2021

Code answers related to "how to copy text from input through button click js"

Code answers related to "Javascript"

Browse Popular Code Answers by Language