Last active
January 3, 2016 05:19
-
-
Save Julow/8415008 to your computer and use it in GitHub Desktop.
Select the text of an element
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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