
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.');

π More Webtips
Master the Art of Frontend
Access exclusive interactive lessons
Unlimited access to hundreds of tutorials
Remove ads to learn without distractions