Answer the question
In order to leave comments, you need to log in
How to make a similar input with a button?
How to make a similar input with a button so that it has a link and can be copied by clicking on the button?
css styles if not needed, only the principle of operation)
Answer the question
In order to leave comments, you need to log in
https://developer.mozilla.org/en-US/docs/Web/API/D...
here is the function.
var copyTextareaBtn = document.querySelector('.js-textareacopybtn');
copyTextareaBtn.addEventListener('click', function(event) {
var copyTextarea = document.querySelector('.js-copytextarea');
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');
}
});
<p>
<button class="js-textareacopybtn" style="vertical-align:top;">Copy Textarea</button>
<textarea class="js-copytextarea">Hello I'm some text</textarea>
</p>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question