Skip to content

Instantly share code, notes, and snippets.

@di3
Created May 9, 2017 06:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save di3/140154084dd4e1872137c943d7c598ec to your computer and use it in GitHub Desktop.
Save di3/140154084dd4e1872137c943d7c598ec to your computer and use it in GitHub Desktop.
select text javascript
//select text inside element
function selectText(e){
var t,n,o=document,a=window,c=o.body,l="unbdefined";
typeof a.getSelection!=l&&typeof o.createRange!=l?(n=o.createRange(),n.selectNodeContents(e),t=a.getSelection(),t.removeAllRanges(),t.addRange(n)) : typeof o.selection!=l&&typeof c.createTextRange!=l&&(n=c.createTextRange(),n.moveToElementText(e),n.select())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment