[whatwg] document.head

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


Was there any discussion for including "document.head" in HTML5?   
Searching the mailing list shows document.head show up a few times in  
example code [1][2].  However, there has been no proposal, and it is  
not mentioned in the document's IDL [3] in the Spec.

Developers often do the following to get a reference to the <head>  
element (top 2 google results) [4]:

     var head = document.getElementsByTagName('head')[0];

Its useful for developers to use that reference to manipulate/append  
stylesheets, scripts, and <style> elements which are only valid inside  
the <head> when the scope attribute is absent [5].

I feel this would be useful to add.  It is confusing that there is a  
"document.body" but no "document.head".  If added, code that interacts  
with the <head> would be much clearer then the current popular  
approach (shown above).  Also, the current approach, barring  
optimizations in the engine, could search the entire DOM tree.

Cheers,
Joseph Pecoraro

[1]: http://lists.whatwg.org/htdig.cgi/whatwg-whatwg.org/2009-March/018835.html
[2]: http://lists.whatwg.org/htdig.cgi/whatwg-whatwg.org/2007-May/011561.html
[3]: http://www.whatwg.org/specs/web-apps/current-work/#documents-in-the-dom
[4]: http://www.google.com/search?hl=en&client=safari&rls=en&q=get+head+element+with+javascript&aq=f&oq=&aqi=
[5]: http://www.whatwg.org/specs/web-apps/current-work/#the-style-element


More information about the whatwg mailing list