W3C home > Mailing lists > Public > whatwg@whatwg.org > September 2009

[whatwg] document.head

From: Joseph Pecoraro <joepeck02@gmail.com>
Date: Sun, 20 Sep 2009 23:17:38 -0400
Message-ID: <4D5AC205-978D-48C1-87FE-B6CE666CC60F@gmail.com>
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

This archive was generated by hypermail 2.3.1 : Monday, 13 April 2015 23:08:52 UTC