Created
October 7, 2020 09:26
-
-
Save rabbitix/f8566332da5e65da8f9a5e181ef06502 to your computer and use it in GitHub Desktop.
copy to clipboard js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function copyDivToClipboard() { | |
var range = document.createRange(); | |
range.selectNode(document.getElementById("toCopy")); | |
window.getSelection().removeAllRanges(); // clear current selection | |
window.getSelection().addRange(range); // to select text | |
document.execCommand("copy"); | |
window.getSelection().removeAllRanges();// to deselect | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment