![How to Copy to Clipboard in JavaScript](https://allma.si/blog/wp-content/uploads/2020/08/javascript-copy.png)
How to Copy to Clipboard in JavaScript
Use document.execCommand
in JavaScript to programmatically copy selected texts. Make sure you select something beforehand.
Copied to clipboard!
document.querySelector('#social-share-link').select();
document.execCommand('copy');
console.log('π Copied to clipboard.');
![How to Copy to Clipboard in JavaScript](https://allma.si/blog/wp-content/uploads/2020/08/javascript-copy-1024x1024.png)
π More Webtips
![Mentoring](/assets/img/mentoring.png)
Rocket Launch Your Career
Speed up your learning progress with our mentorship program. Join as a mentee to unlock the full potential of Webtips and get a personalized learning experience by experts to master the following frontend technologies: