Im working with jQuery. There are input fields with ID’s and attached .blur() events. The problem comes when I try to figure out the very new item where the focus is on:
$("#"+field).blur(function()
{
console.log ($(this).attr('id')+' -> '+$("*:focus").attr('id'));
}
but this $(“*:focus”).attr(‘id’) is undefined. How to detect where is the focus?
It would seem the blur/focus events are fired before a new element actually gets the
:focuspseudo-class attached to it. Which is pretty interesting. Proof of what I mean in this fiddleSo that begs the question – why are you trying to do this? 🙂
My solution to your problem (if you absolutely need it like that) is to do it like so : FIDDLE