Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.