Skip to content

Instantly share code, notes, and snippets.

@mertenvg
Created January 23, 2013 11:18
Show Gist options
  • Save mertenvg/4604536 to your computer and use it in GitHub Desktop.
Save mertenvg/4604536 to your computer and use it in GitHub Desktop.
Set the selection to the contents of the specified DOM element.
function select_contents(element) {
var selection = window.getSelection();
var range = document.createRange();
range.selectNodeContents(element);
selection.removeAllRanges();
selection.addRange(range);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment