Skip to content

Instantly share code, notes, and snippets.

@wesleybliss
Created December 17, 2020 15:01
Show Gist options
  • Save wesleybliss/3d60698d532a6c58d3beae32ba573f39 to your computer and use it in GitHub Desktop.
Save wesleybliss/3d60698d532a6c58d3beae32ba573f39 to your computer and use it in GitHub Desktop.
Select text #js
export const selectText = el => {
if (!window.getSelection || !document.createRange) return
const sel = window.getSelection()
if (sel.toString() == '')
window.setTimeout(() => {
const range = document.createRange()
range.selectNodeContents(el)
sel.removeAllRanges()
sel.addRange(range)
}, 1)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment