How to determine which element gets focus in blur()?
Is it possible to find the element that currently has the focus in a cross-browser way?
In IE, it is possible to do $(x).blur(function(evt) { alert('Focus goes to ' + evt.toElement.id); });
and I need to do something similar in other browsers.
As an alternative, if its possible, I could do a setTimeout and then investigate the currently focu开发者_运维知识库sed element, but I don't know to do that either.
You could just remember what was focused in a variable. Variable scope in JS works cross-browser :)
(function($){
var focused;
$(commonParentForElements).on('focus','input',function(e){
focused = e.target;
}).on('blur','input',function(e){
//do stuff with focused
//when done, clean up
focused = null;
})
})(jQuery);
精彩评论