🎄 Get 50% off from our JavaScript course for the holidays! 🎄
How to Copy to Clipboard in JavaScript

How to Copy to Clipboard in JavaScript

Ferenc Almasi • 2020 August 08 • 📖 1 min read

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.');
copy.js
Copied to clipboard!
How to Copy to Clipboard in JavaScript
If you would like to see more Webtips, follow @flowforfrank
JavaScript Course Dashboard

Tired of looking for tutorials?

You are not alone. Webtips has more than 400 tutorials which would take roughly 75 hours to read.

Check out our interactive course to master JavaScript in less time.

Learn More

Recommended

🎉 Thank you for subscribing to our newsletter. x