I'm looking for a cross-browser method - I know IE has something (I've already forgotten what), and the way to do it in Mozilla may have to do with a focusNode thing I found, that seems related to getting text selections.
Methods involving jQuery or another common JS library are fine by me.
Thanks!
Check out the extra selectors plugin for jQuery, it includes a :focus
selector that answers your need. You can use just the implementation of that selector if you don't the rest.
OK then, so use jQuery.
There is no current, available way to just ask this. You need to track the focus events when they happen, so this sample (thanks to Karl Rudd here) does that across all elements. This is for inputs but you can adjust the selector to fit your needs, even across the entire DOM.
var currentFocus = null;
$(':input').focus( function() {
currentFocus = this;
}).blur( function() {
currentFocus = null;
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With