Skip to content

Instantly share code, notes, and snippets.

@eloone
Created May 15, 2014 20:13
Show Gist options
  • Save eloone/77c702bde112a0758763 to your computer and use it in GitHub Desktop.
Save eloone/77c702bde112a0758763 to your computer and use it in GitHub Desktop.
var range = document.createRange();//Create a range (a range is a like the selection but invisible)
range.selectNodeContents(this.target);//Select the entire contents of the element with the range
range.setEnd(this.target.firstChild, pos);
range.collapse();//collapse the range to the end point. false means collapse to end rather than the start
selection = window.getSelection();//get the selection object (allows you to change selection)
selection.removeAllRanges();//remove any selections already made
selection.addRange(range);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment