Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

On click copy text

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 :: javascript round number to 5 decimal places 
Javascript :: javascript execute powershell script 
Javascript :: shorthand if statment in js 
Javascript :: angular capitalize first letter 
Javascript :: datatables get all checkboxes with pagination 
Javascript :: lowercase to uppercase in javascript 
Javascript :: How to access the GET parameters after “?” in Express 
Javascript :: how to rotate an array in javascript 
Javascript :: javascript convert string with square brackets to array 
Javascript :: jquery post 
Javascript :: regex js pattern tags 
Javascript :: poll in javascript 
Javascript :: reverse string with recursion 
Javascript :: user input in js 
Javascript :: add toaster in angular 
Javascript :: Material-ui add comment icon 
Javascript :: How to get latitude and longitude from address in angular 6 
Javascript :: use setstate in function component 
Javascript :: how to play audio in javascript 
Javascript :: search datatable vuetify 
Javascript :: react 18 
Javascript :: webpack-bundle-analyzer react 
Javascript :: react-active link 
Javascript :: usecallback vs usememo 
Javascript :: django ajax body to json 
Javascript :: js loop through object keys 
Javascript :: how to import svg in react 
Javascript :: vuejs vscode unbound breakpoint 
Javascript :: how to convert string to sentence case in javascript 
Javascript :: javascript concat two arrays 
ADD CONTENT
Topic
Content
Source link
Name
7+7 =