Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save gubatron/6599366 to your computer and use it in GitHub Desktop.
Save gubatron/6599366 to your computer and use it in GitHub Desktop.
function selectText(element) {
var doc = document
, text = doc.getElementById(element)
, range, selection
;
if (doc.body.createTextRange) { //ms
range = doc.body.createTextRange();
range.moveToElementText(text);
range.select();
} else if (window.getSelection) { //all others
selection = window.getSelection();
range = doc.createRange();
range.selectNodeContents(text);
selection.removeAllRanges();
selection.addRange(range);
}
}
@gubatron
Copy link
Author

wow, glad you found it and it still works, had totally forgotten about this gist.

Cheers!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment