The closest thing to a specification about this is probably the description of focus in HTML5 CR (which is work in progress, “a draft document and may be updated, replaced or obsoleted by other documents at any time”, but in practice close to a consensus). It says: “There may be no element focused; when no element is focused, key events received by the document must be targeted at the body element, if there is one, or else at the Document's root element, if there is one. If there is no root element, key events must not be fired.”
Since the blur()
method is defined (in DOM 2 HTML spec) simply as removing focus, it means leaving a page in a state where no element is focused. But this may look like the body
element were focused: if you have, say, a keypress
attribute on it, it gets triggered. This however differs from the focused state. For example, in this situation, the body
element does not match the CSS selector :focus
.
The conclusion is that you should normally avoid using blur()
and do focus()
on some suitable focusable element instead, as suggested in other answers. An exception is a situation where you just want to discard all keyboard events. Then blur()
is OK, provided that your code does not assign any keyboard event handlers to the body
element.