Skip to content

Instantly share code, notes, and snippets.

@SergSlon
Last active December 17, 2015 12:24
Show Gist options
  • Select an option

  • Save SergSlon/5c1592d7388fd1effa78 to your computer and use it in GitHub Desktop.

Select an option

Save SergSlon/5c1592d7388fd1effa78 to your computer and use it in GitHub Desktop.
jquery selectRange
//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