Created
February 7, 2017 17:06
-
-
Save dustinpoissant/16444234168d94a3d99a9c09c2606b22 to your computer and use it in GitHub Desktop.
Selects the text within 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
jQuery.fn.selectText = function(){ | |
var doc = document; | |
var element = this[0]; | |
if (doc.body.createTextRange) { | |
var range = document.body.createTextRange(); | |
range.moveToElementText(element); | |
range.select(); | |
} else if (window.getSelection) { | |
var selection = window.getSelection(); | |
var range = document.createRange(); | |
range.selectNodeContents(element); | |
selection.removeAllRanges(); | |
selection.addRange(range); | |
} | |
}; |
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
jQuery.fn.selectText=function(){var a=document,b=this[0];if(a.body.createTextRange){var c=document.body.createTextRange();c.moveToElementText(b),c.select()}else if(window.getSelection){var d=window.getSelection(),c=document.createRange();c.selectNodeContents(b),d.removeAllRanges(),d.addRange(c)}}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment