Skip to content

Instantly share code, notes, and snippets.

@Julow
Last active January 3, 2016 05:19
Show Gist options
  • Save Julow/8415008 to your computer and use it in GitHub Desktop.
Save Julow/8415008 to your computer and use it in GitHub Desktop.
Select the text of an element
function selectText(element)
{
if(document.body.createTextRange) // ie
{
var range = document.body.createTextRange();
range.moveToElementText(element);
range.select();
}
else if(window.getSelection)
{
var range = document.createRange();
range.selectNodeContents(element);
var selection = window.getSelection();
selection.removeAllRanges();
selection.addRange(range);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment