Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

javascript click to copy

function copyToClipboard(value) {
  navigator.clipboard.writeText(value)
}
Comment

how to enable click copy function using js

var copyTextareaBtn = document.querySelector('.js-textareacopybtn');

copyTextareaBtn.addEventListener('click', function(event) {
  var copyTextarea = document.querySelector('.js-copytextarea');
  copyTextarea.focus();
  copyTextarea.select();

  try {
    var successful = document.execCommand('copy');
    var msg = successful ? 'successful' : 'unsuccessful';
    console.log('Copying text command was ' + msg);
  } catch (err) {
    console.log('Oops, unable to copy');
  }
});

////html code below
<p>
  <button class="js-textareacopybtn" style="vertical-align:top;">Copy Textarea</button>
  <textarea class="js-copytextarea">Hello I'm some text</textarea>
</p>
Comment

PREVIOUS NEXT
Code Example
Javascript :: get domain name with regex 
Javascript :: angular pipe percentage 
Javascript :: get user time using timezone javascript 
Javascript :: mysql remove quote on json extract 
Javascript :: js execute string 
Javascript :: how to use trim in node js 
Javascript :: async import javascript 
Javascript :: cookie clicker hack extension 
Javascript :: ref focus not working vue js 
Javascript :: storage class 
Javascript :: scroll to top router link vue 
Javascript :: is function javascript 
Javascript :: complete math objects in javascript 
Javascript :: run function then empty it javascript 
Javascript :: call a function multiple times 
Javascript :: javascript getcontext 
Javascript :: create react app command 
Javascript :: js hexadecimal 
Javascript :: header disallowed by preflight response in express 
Javascript :: If statement discord js 
Javascript :: convert string to uppercase 
Javascript :: math.min 
Javascript :: event module in node js 
Javascript :: how to get range slider value in javascript 
Javascript :: useReducer 
Javascript :: how to export a constant in javascript 
Javascript :: at in js 
Javascript :: create fooer on print page with jquery 
Javascript :: export gcp credentials json file 
Javascript :: import library react js 
ADD CONTENT
Topic
Content
Source link
Name
2+2 =