Skip to content

Instantly share code, notes, and snippets.

@cowboy
Created June 23, 2010 14:47
Show Gist options
  • Save cowboy/450017 to your computer and use it in GitHub Desktop.
Save cowboy/450017 to your computer and use it in GitHub Desktop.
:focus - get the currently focused element
// Public domain, really.
jQuery.expr[':'].focus = function( elem ) {
return elem === document.activeElement && ( elem.type || elem.href );
};
@mathiasbynens
Copy link

@dperini I wasn’t trying to be funny, just pointing it out. I very much agree it would be nonsensical to write additional code to take into account these weird and highly unlikely situations.

@gnarf
Copy link

gnarf commented May 4, 2011

Should this maybe also check for some element that is not an input that has tabIndex ?

@pnina
Copy link

pnina commented Jun 2, 2011

please you send me a sample how to use this selector (:focus) ?

@cowboy
Copy link
Author

cowboy commented Jun 2, 2011

It works like this: :focus selector (note that recent versions of jQuery include this selector)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment