Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <script>
- function copyToClipboard(elementId) {
- // Create a "hidden" input
- var aux = document.createElement("input");
- // Assign it the value of the specified element
- aux.setAttribute("value", document.getElementById(elementId).innerHTML);
- // Append it to the body
- document.body.appendChild(aux);
- // Highlight its content
- aux.select();
- // Copy the highlighted text
- document.execCommand("copy");
- // Remove it from the body
- document.body.removeChild(aux);
- }
- </script>
- <button onclick="copyToClipboard('copy-to-clipboard')">copy to clipboard</button>
Advertisement
Add Comment
Please, Sign In to add comment