Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

Copy text on click

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"))
  }
});
Comment

PREVIOUS NEXT
Code Example
Javascript :: pattern validator angular 
Javascript :: If statement discord js 
Javascript :: document queryselectorall and map javacript 
Javascript :: request animation frame 
Javascript :: floating button react 
Javascript :: uppercase javascript using function 
Javascript :: npm is not recognized 
Javascript :: how to remove more than one attribute using jquery 
Javascript :: kendo treeview get selected node data 
Javascript :: how to use console.log in vuejs 
Javascript :: event module in node js 
Javascript :: how to poll efficiently in javascript 
Javascript :: MongoDb user find 
Javascript :: array every javascript 
Javascript :: javascript redirect with extra url arguments 
Javascript :: how to find date in a string js 
Javascript :: sqrt javascript 
Javascript :: split array into chunks javascript 
Javascript :: .on click jquery 
Javascript :: react native paper modal background 
Javascript :: javascript get main color from image 
Javascript :: import library react js 
Javascript :: next js page loader 
Javascript :: how to make an array in javascript 
Javascript :: js get node index 
Javascript :: js object some 
Javascript :: get url query in react 
Javascript :: console log return from async 
Javascript :: elastic get data from specific fields 
Javascript :: javascript count character in string 
ADD CONTENT
Topic
Content
Source link
Name
2+5 =