Skip to content

Instantly share code, notes, and snippets.

@ziluo
Created July 5, 2013 05:47
Show Gist options
  • Save ziluo/5932206 to your computer and use it in GitHub Desktop.
Save ziluo/5932206 to your computer and use it in GitHub Desktop.
select 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