[whatwg] document.head

Joseph Pecoraro joepeck02 at gmail.com
Sun Sep 20 20:17:38 PDT 2009

On Sep 20, 2009, at 10: 29PM, Garrett Smith wrote:
>> On Sun, 20 Sep 2009 16:15:11 -0400, Joseph Pecoraro <joepeck02 at gmail.com 
>> >
>>> Something like this almost always works:
>>>   var head = document.documentElement.firstChild
> The documentElement.firstChild cannot be expected to be head. It could
> be a text node. For example:-
> <html>
>   <head>
> ...
> the first child node of HTML looks like a textNode with the value
> "\n\n\u0020\u0020".
> document.getElementsByTagName("head")[0] could be expected to produce
> (in a valid HTML document) a result that is more consistent than
> document.firstChild.

Even despite the white space, I got the <head> element in Safari,  
Firefox, and Opera.  But, you're absolutely right, I'm not saying my  
suggestion is bulletproof, only that it can be expected to perform far  

However, I am interested in seeing a solution that is bulletproof and  
one that performs well!  Namely, "document.head".

- Joe

More information about the whatwg mailing list