Skip to content

Instantly share code, notes, and snippets.

@emersonbrogadev
Created July 18, 2019 16:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save emersonbrogadev/c2aa20d1d0070b807273cdaa50dff315 to your computer and use it in GitHub Desktop.
Save emersonbrogadev/c2aa20d1d0070b807273cdaa50dff315 to your computer and use it in GitHub Desktop.
Copy (CTRL + C) com JavaScript
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<input id="text" />
<button id="copy">Copy</button>
<script type="text/javascript">
const textInput = document.getElementById('text');
const copyButton = document.getElementById('copy');
copyButton.addEventListener('click', ()=> {
textInput.select();
document.execCommand('copy');
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment