Created
April 20, 2018 11:31
-
-
Save rista404/6a68668f0915d828650c42de57d8d756 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 selectText(element) { | |
let range | |
let selection | |
if (document.body.createTextRange) { | |
//ms | |
range = document.body.createTextRange() | |
range.moveToElementText(element) | |
range.select() | |
} else if (window.getSelection) { | |
//all others | |
selection = window.getSelection() | |
range = document.createRange() | |
range.selectNodeContents(element) | |
selection.removeAllRanges() | |
selection.addRange(range) | |
} | |
return selection.toString() || range.toString() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment