Created
May 18, 2012 21:11
-
-
Save raulb/2727627 to your computer and use it in GitHub Desktop.
Cross browser select text
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) { | |
var text = document.getElementById(element); | |
if ($.browser.msie) { | |
var range = document.body.createTextRange(); | |
range.moveToElementText(text); | |
range.select(); | |
} else if ($.browser.mozilla || $.browser.opera) { | |
var selection = window.getSelection(); | |
var range = document.createRange(); | |
range.selectNodeContents(text); | |
selection.removeAllRanges(); | |
selection.addRange(range); | |
} else if ($.browser.safari) { | |
var selection = window.getSelection(); | |
selection.setBaseAndExtent(text, 0, text, 9999); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment