Skip to content

Instantly share code, notes, and snippets.

@Narga
Created June 7, 2012 02:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Narga/2886218 to your computer and use it in GitHub Desktop.
Save Narga/2886218 to your computer and use it in GitHub Desktop.
jQuery script to choose the mouse cursor position when I click on input field
//http://www.narga.net/making-awesome-forms-inline-labels-with-jquery
$.fn.setCursorPosition = function(pos) {
if ($(this).get(0).setSelectionRange) {
$(this).get(0).setSelectionRange(pos, pos);
} else if ($(this).get(0).createTextRange) {
var range = $(this).get(0).createTextRange();
range.collapse(true);
range.moveEnd('character', pos);
range.moveStart('character', pos);
range.select();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment