Re: [whatwg] Document.activeElement should return the root element in non-HTML documents when no element has focus

On Mon, 3 Feb 2014, Anne van Kesteren wrote:
> On Mon, Feb 3, 2014 at 3:34 AM, Cameron McCormack <cam@mcc.id.au> wrote:
> > When the document isn't an HTML document and when there is no element 
> > with focus.  Browsers agree on returning null in an HTML document when 
> > there is no element with focus, no <body> element, but still a 
> > document element.

That case is obscure, though (I mean, it can only happen if you literally 
replace the <body> or <frameset> element with something else, like a 
<div>... and while I acknowledge that the Web is a wild, wild place, I 
doubt there are many pages that actually do that and, on top of that, 
depend on activeElement returning null).

It seems simpler to just try to use "the body element" (as defined in the 
HTML spec, it's not a <body> necessarily), and if that fails, use the root 
if there is one or null otherwise.


On Mon, 3 Feb 2014, Boris Zbarsky wrote:
>
> What Gecko does is that if the document is an HTMLDocument (so is 
> text/html or application/xhtml+xml) and hence has a .body property we 
> use that.  Otherwise we use .documentElement.
> 
> Of course the spec has no concept of HTMLDocument and has a .body on all 
> documents...

Yeah, that would hurt the ability to use HTML from other namespaces (since 
the HTML helper stuff on the Document would be missing).

-- 
Ian Hickson               U+1047E                )\._.,--....,'``.    fL
http://ln.hixie.ch/       U+263A                /,   _.. \   _\  ;`._ ,.
Things that are impossible just take longer.   `._.-(,_..'--(,_..'`-.;.'

Received on Monday, 3 February 2014 19:42:56 UTC