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

js copy paragraph onclick

var copy = document.querySelectorAll(".copy"); 

for (const copied of copy) { 
  copied.onclick = function() { 
    document.execCommand("copy"); 
  };  
  copied.addEventListener("copy", function(event) { 
    event.preventDefault(); 
    if (event.clipboardData) { 
      event.clipboardData.setData("text/plain", copied.textContent);
      console.log(event.clipboardData.getData("text"))
    };
  });
};
Comment

code of copy button in js

var
 i 
=
34
;
copy
Comment

PREVIOUS NEXT
Code Example
Javascript :: show 10 entries datatable jquery hide 
Javascript :: js isprome 
Javascript :: mongoose string index 
Javascript :: learn gram js 
Javascript :: nextjs build failed optimization killed 
Javascript :: how to repeat prompt with the same variable in javascript 
Javascript :: how use for loop in append attribute in jquery 
Javascript :: node-schedule-tz print jobs 
Javascript :: angular readonly/Disabled if value is not null 
Javascript :: jquery set multiple css properties 
Javascript :: iso string to timestamp javascript 
Javascript :: use history react router dom 
Javascript :: react count up every second 
Javascript :: javascript onclick event listener 
Javascript :: Required a safe HTML, got a ResourceURL 
Javascript :: remove element from array javascript 
Javascript :: update the whole target of a proxy javascript 
Javascript :: negative reciprocal javascript 
Javascript :: discord.js reliablehandler 
Javascript :: how to delay execution in nodejs 
Javascript :: find array object value is already in use 
Javascript :: shopping cart small icon code react-bootstrap 4.6 fa fas 
Javascript :: __dirname go back one directory 
Javascript :: ohmyscript.com 
Javascript :: angular ngmodel subject 
Javascript :: jspdf addimage 
Javascript :: vanilla javascript set display 
Javascript :: how to check if iframe is loaded 
Javascript :: mongoose pull each 
Javascript :: update object in react hooks 
ADD CONTENT
Topic
Content
Source link
Name
8+2 =