Skip to content

Instantly share code, notes, and snippets.

@alphamarket
Last active August 9, 2018 14:35
Show Gist options
  • Save alphamarket/450e860d5819d7a7430a9b6a1b6af889 to your computer and use it in GitHub Desktop.
Save alphamarket/450e860d5819d7a7430a9b6a1b6af889 to your computer and use it in GitHub Desktop.
jQuery.focus() and move cursor at the end of input
# jQuery extensions
(($) ->
_super = { }
#
# [..] some other extensions
#
_super.focus = $.fn.focus
$.fn.focus = ->
# call out the original jQuery focus
_super.focus.apply(this, arguments)
# set cursor at the end of val
v = this.val()
this.val('')
this.val(v)
this
return
) jQuery
# javaScript compilation:
#
# (function($) {
# var _super = {};
# _super.focus = $.fn.focus;
# $.fn.focus = function() {
# var v;
# _super.focus.apply(this, arguments);
# v = this.val();
# this.val('');
# this.val(v);
# return this;
# };
# })(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment