Last active
December 17, 2015 12:24
-
-
Save SergSlon/5c1592d7388fd1effa78 to your computer and use it in GitHub Desktop.
jquery selectRange
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
| //SELECT TEXT RANGE | |
| $.fn.selectRange = function(start, end) { | |
| return this.each(function() { | |
| if (this.setSelectionRange) { | |
| this.focus(); | |
| this.setSelectionRange(start, end); | |
| } else if (this.createTextRange) { | |
| var range = this.createTextRange(); | |
| range.collapse(true); | |
| range.moveEnd('character', end); | |
| range.moveStart('character', start); | |
| range.select(); | |
| } | |
| }); | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment