Answers for "on click copy to clipboard js"

56

javascript text to clipboard

function copyToClipboard(text) {
   const elem = document.createElement('textarea');
   elem.value = text;
   document.body.appendChild(elem);
   elem.select();
   document.execCommand('copy');
   document.body.removeChild(elem);
}
Posted by: Guest on March-20-2020
0

how copy url of page to clipboard javascript

var $temp = $("<input>");
var $url = $(location).attr('href');

$('.clipboard').on('click', function() {
  $("body").append($temp);
  $temp.val($url).select();
  document.execCommand("copy");
  $temp.remove();
  $("p").text("URL copied!");
})
Posted by: Guest on December-13-2021

Code answers related to "on click copy to clipboard js"

Code answers related to "Javascript"

Browse Popular Code Answers by Language