Get the clicked object that triggered jquery blur() event

pillarOfLight picture pillarOfLight · Jul 18, 2012 · Viewed 42.1k times · Source

Suppose I do this:

$(target).blur(function(e){
  //do stuff
});

Is there a way to fetch the object that was clicked on in order to trigger the blur action?

I tried using e.target, but that appears to be returning the object attached to the blur action rather than the clicked object.

Answer

blockhead picture blockhead · Jul 18, 2012

The trick is to wait an extra tick:

$(el).blur(function (event) {
    // If we just hangout an extra tick, we'll find out which element got focus really
    setTimeout(function(){
       document.activeElement; // This is the element that has focus
    },1);
})