Created
November 30, 2018 17:56
-
-
Save cozzbie/641aa7d4b8a63fcc9ab67ab84a1d6c0b to your computer and use it in GitHub Desktop.
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
const selection = window.getSelection(); | |
const range = document.createRange(); | |
const element = document.getElementById('elmt'); | |
// Collect a range based off the contents of an element. | |
range.selectNodeContents(element); | |
// Clear ranges that might be stored in the selection object. | |
selection.removeAllRanges(); | |
selection.addRange(range); | |
//Optional | |
document.execCommand('copy'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment