The focus and blur events keep track of the elements the user focuses on.
That sounds simple, but it isn’t.
The reason focus and blur don’t bubble is that the events mean something quite different on the window and on any other focusable element. These two definitions should not be confused, and therefore the events cannot be allowed to bubble up to the document.
The following elements are focusable:
I did not do these tests on the document; the permutations are hideously complicated and no one in his right mind would set focus or blur events on the document in any case.
Test | IE 5.5 | IE 6 | IE 7 | IE8 | IE9 | IE10 pr2 | FF 7.0 Win | FF 6.1 Mac | Saf 5.1 Win | Saf 5.1 Mac | Chrome 14 Win | Chrome 13 Mac | Opera 11.51 Win | Opera 11.51 Mac |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Window
If the user brings a browser window forward (by clicking on it, using Alt+Tab or manipulating the taskbar),
a focus event on the window fires. Likewise, if the browser window is sent backwards, a blur event fires.
|
Yes | Almost | Too many | Yes | Yes | Yes | ||||||||
|
||||||||||||||
Links
Focus and blur events on links should always fire, regardless of whether the user uses the mouse
or the keyboard.
|
Yes | Yes | No | Incom |
Yes | |||||||||
|
||||||||||||||
Form fields
Focus and blur events on form fields should always fire, regardless of whether the user uses the mouse
or the keyboard.
|
Yes | Yes | Incom |
Incom |
Incom |
Yes | ||||||||
|
||||||||||||||
Test | IE 5.5 | IE 6 | IE 7 | IE8 | IE9 | IE10 pr2 | FF 7.0 Win | FF 6.1 Mac | Saf 5.1 Win | Saf 5.1 Mac | Chrome 14 Win | Chrome 13 Mac | Opera 11.51 Win | Opera 11.51 Mac |
Elements with tabindex
By giving it a tabindex you can make any element you like focusable. The focus and blur events
should work on such elements.
|
Yes | Yes | Yes | Yes | Yes | |||||||||
Window + focusable element
If the window is sent backward while a focusable element is focused, blur events should fire on
both. If the window is brought forward again, focus events should fire on both.
|
Not tested | Too many | Yes | Yes | Too many | Yes | Yes | Incom |
||||||
|
||||||||||||||
Event capturing
Focus and blur events don’t bubble. but they should be captured from the window on downward.
|
Untest |
Yes | Yes | Yes | Yes | Yes | ||||||||
focusin and focusout
Same as focus and blur, but bubble.
|
No | Yes | No | Incom |
Incom |
Yes | ||||||||
|
||||||||||||||
Test | IE 5.5 | IE 6 | IE 7 | IE8 | IE9 | IE10 pr2 | FF 7.0 Win | FF 6.1 Mac | Saf 5.1 Win | Saf 5.1 Mac | Chrome 14 Win | Chrome 13 Mac | Opera 11.51 Win | Opera 11.51 Mac |