views:

18

answers:

2

Forcing focus() on an element is easy, but after having debug issues, I realize trying to determine where is my focus gone is a lot harder. thing is I'm generating a modal window using jq.UI, and from time to time, while focus is supposed to be set on first input of the form inckuded in the modal, cursor just disappears, to never show again unless I reload the page.

Is there a straightforward way to detect where my focus/cursor is ?

Thanks a lot.

+2  A: 

You can see which element it's on by checking document.activeElement, for example:

alert(document.activeElement.innerHTML); //see the content to aid in IDing it
Nick Craver
A: 

I'm not sure if the focus event bubbles, but if it does, you could try this:

jQuery('body').focus(e) { console.log(e.target); };
Thomas