Created
June 23, 2010 14:47
-
-
Save cowboy/450017 to your computer and use it in GitHub Desktop.
:focus - get the currently focused element
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Public domain, really. | |
jQuery.expr[':'].focus = function( elem ) { | |
return elem === document.activeElement && ( elem.type || elem.href ); | |
}; |
@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.
Should this maybe also check for some element that is not an input that has tabIndex
?
please you send me a sample how to use this selector (:focus) ?
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
@mathiasbynens,
ha...ha... what for ?
If you want to fake the test or the selector engine or the browsers CSS engine you will be able to do it under all circumstances. Just set the "type" or "href" property of each element in the page. The check could test the nodeName of valid focusable elements to make it stronger but it will be useful only for you and your non-standard approach and that has no value for me.