Created
January 25, 2013 23:51
-
-
Save stefanocudini/4638963 to your computer and use it in GitHub Desktop.
plugin jquery for select html element
This file contains hidden or 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($){ | |
| $.fn.selText = function() { | |
| var obj = this[0]; | |
| if ($.browser.msie) { | |
| var range = obj.offsetParent.createTextRange(); | |
| range.moveToElementText(obj); | |
| range.select(); | |
| } else if ($.browser.mozilla || $.browser.opera) { | |
| var selection = obj.ownerDocument.defaultView.getSelection(); | |
| var range = obj.ownerDocument.createRange(); | |
| range.selectNodeContents(obj); | |
| selection.removeAllRanges(); | |
| selection.addRange(range); | |
| } else if ($.browser.safari) { | |
| var selection = obj.ownerDocument.defaultView.getSelection(); | |
| selection.setBaseAndExtent(obj, 0, obj, 1); | |
| } | |
| return this; | |
| } | |
| }) (jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment