
How to Copy to Clipboard in JavaScript
Use document.execCommand
in JavaScript to programmatically copy selected texts. Make sure you select something beforehand.
document.querySelector('#social-share-link').select();
document.execCommand('copy');
console.log('π Copied to clipboard.');
Copied to clipboard!

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