This question already has an answer here:
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.
The trick is to wait an extra tick:
If I understand your question correctly, this should do it:
Using this within
blur
handler function will give you theblured
element.Within
blur
event you can't catch the clicked element. To get theclick
ed element you needclick
event. For example:And to get the focused element you can use
:focus
selector like:$(':focus')
will returns you focused element in document.Inside an event handler,
this
will be the element the event is bound to, ande.target
will be the element that triggered the event (may or not be the same asthis
).You are handing a
blur
event, not aclick
event. So, inside your event, you will have the element that youblur
ed. If you want theclick
ed element, you'd need another event to get that.blur
can be triggered by other events, such as focusing something; not just clicking on something. So, there is no way to get the element that "caused the blur".