views:

389

answers:

2

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!

+1  A: 

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;

});

ironfroggy
+3  A: 

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.

Eran Galperin