[whatwg] document.head

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  
better!

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

Cheers,
- Joe

Received on Sunday, 20 September 2009 20:17:38 UTC