Skip to content

Instantly share code, notes, and snippets.

@nborko
Created March 28, 2016 18:34
Show Gist options
  • Save nborko/03c1f9be3bce55069287 to your computer and use it in GitHub Desktop.
Save nborko/03c1f9be3bce55069287 to your computer and use it in GitHub Desktop.
jQuery shim to focus on any element regardless of tabindex
/* jquery shim to focus on any element regardless of tabindex */
(function($) {
$.fn.focus = (function(focus) {
return function () {
if (arguments.length > 0) {
return focus.apply(this, arguments);
}
if (typeof $(this).attr('tabindex') === 'undefined') {
return focus.call(this.attr('tabindex', '-1')).removeAttr('tabindex');
}
return focus.call(this);
};
})($.fn.focus);
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment